Language: C++

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
int main(){
	int n,r;
	cin >> n;
	cin.ignore();
	while(n--){
		int cur = 0;
		string text, command;
		getline(cin, text);
		int len = text.size();
		cin	>> r;
		cin.ignore();
		while(r--){
			getline(cin, command);
			if(command == "forward char"){
				cur=min(len, cur+1);
			}else if(command == "forward word"){
				for(;cur<len && text[cur] == ' '; cur++);
				for(;cur<len && text[cur] != ' '; cur++);
			}else if(command == "backward char"){
				cur=max(0, cur-1);
			}else if(command == "backward word"){
				for(;cur>0 && text[cur-1] == ' '; cur--);
				for(;cur>0 && text[cur-1] != ' '; cur--);
			}else if(command == "delete char"){
				if(cur>=len) continue;
				text.erase(text.begin()+cur);
				len--;
			}else if(command == "delete word"){
				int s = cur;
				for(;s<len && text[s] == ' '; s++){
					#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
int main(){
	int n,r;
	cin >> n;
	cin.ignore();
	while(n--){
		int cur = 0;
		string text, command;
		getline(cin, text);
		int len = text.size();
		cin	>> r;
		cin.ignore();
		while(r--){
			getline(cin, command);
			if(command == "forward char"){
				cur=min(len, cur+1);
			}else if(command == "forward word"){
				for(;cur<len && text[cur] == ' '; cur++);
				for(;cur<len && text[cur] != ' '; cur++);
			}else if(command == "backward char"){
				cur=max(0, cur-1);
			}else if(command == "backward word"){
				for(;cur>0 && text[cur-1] == ' '; cur--);
				for(;cur>0 && text[cur-1] != ' '; cur--);
			}else if(command == "delete char"){
				if(cur>=len) continue;
				text.erase(text.begin()+cur);
				len--;
			}else if(command == "delete word"){
				int s = cur;
				for(;s<len && text[s] == ' '; s++){
					text.erase(text.begin()+s);
					len--;
				}
				for(;s<len && text[s] != ' ';){
					text.erase(text.begin()+s);
					len--;
				}
			}else if(command.find("insert")!=command.npos){
				string ins;
				int s = command.find('"');
				int t = command.find('"',s+1);
				ins = command.substr(s+1,t-s-1);
				text.insert(cur,ins);
				len+=t-s-1;
				cur+=t-s-1;
			}
			
		}
		cout<<text.substr(0,cur)<<"^"<<text.substr(cur)<<endl;
	}

	return 0;
}

				}
				for(;s<len && text[s] != ' ';){
					text.erase(text.begin()+s);
					len--;
				}
			}else if(command.find("insert")!=command.npos){
				string ins;
				int s = command.find('"');
				int t = command.find('"',s+1);
				ins = command.substr(s+1,t-s-1);
				text.insert(cur,ins);
				len+=t-s-1;
				cur+=t-s-1;
			}
			
		}
		text.insert(text.begin()+cur,'^');
		cout << text << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   43 | int main(){
      |         ^~
a.cc:43:9: note: remove parentheses to default-initialize a variable
   43 | int main(){
      |         ^~
      |         --
a.cc:43:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:43:11: error: a function-definition is not allowed here before '{' token
   43 | int main(){
      |           ^