Language: C++

{
  string str;
  char c;
  c = _space();
  if (c == '\n') return str;
  do {
    str+=c;
  } while ((c = getchar()) != '\n');

  return string(str);
}

string nextQuote()
{
  space();
  char c;
  string str = "";
  while ((c = getchar()) != '"') {
    str += c;
  }
  return str;
}

int main()
{
  int nTest;  
  scanf("%d ",&nTest);
  //cout << nTest << endl;
    
  for (int testIdx = 0; testIdx < nTest; testIdx++) {
    string text = nextLine();
    //cout << text << endl;
    //    cin.ignore();

    int N;
    scanf(" %d ", &N);
    //cout << "N = " << N << endl;
    //cin.ignore();
    int cur = 0;
    for (int i = 0; i < N; i++) {
      string cmd, arg;
      cmd = nextStr();
      if (cmd == "forward") {
	arg = nextStr();
	if (arg == "char") {
	  if (cur < text.size()) {
	    cur++;
	  }
	} else {	
	  while (cur < text.size() && isblank(text[cur])) {cur++;}
	  while (cur < text.size() && !isblank(text[cur])) {cur++;}
	}
      } else if (cmd == "backward") {
	arg = nextStr();
	if (arg == "char") {
	  if (cur > 0) {
	    cur--;
	  }
	} else {	  
	  while (cur > 0 && !isblank(text[cur])) {cur--;}
	  //while (cur > 0 && isblank(text[cur])) {cur--;}
	}
      } else if (cmd == "insert") {
	arg = nextQuote();
	text.insert(text.begin() + cur, arg.begin(), arg.end());
	cur += arg.size();
      } else if (cmd == "delete") {
	arg = nextStr();
	if (arg == "char") {
	  if (cur < text.size()) {
	    text.erase(text.begin() + cur);
	  }
	} else {
	  while (cur < text.size() && isblank(text[cur])) {
	    text.erase(text.begin() + cur);
	  }
	  while (cur < text.size() && !isblank(text[cur])) {
	    text.erase(text.begin() + cur);
	  }
	  /*
	  */
	}
      }
      //cout << "cmd, arg = " << cmd << ", " << arg << endl;
      //cout << "cur = " << cur << endl;
      //cout << text << endl;
    }
    for (int i = 0; i < cur; i++) {
      cout << text[i];
    }
    cout << "^";
    for (int i = cur; i < text.size(); i++) {
      cout << text[i];
    }
    cout << endl;
  }
  return 0;
}

Compiler output:
a.cc:1:1: error: expected unqualified-id before '{' token
    1 | {
      | ^
a.cc:13:1: error: 'string' does not name a type
   13 | string nextQuote()
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:27:3: error: 'scanf' was not declared in this scope
   27 |   scanf("%d ",&nTest);
      |   ^~~~~
a.cc:31:5: error: 'string' was not declared in this scope
   31 |     string text = nextLine();
      |     ^~~~~~
a.cc:41:13: error: expected ';' before 'cmd'
   41 |       string cmd, arg;
      |             ^~~~
      |             ;
a.cc:42:7: error: 'cmd' was not declared in this scope
   42 |       cmd = nextStr();
      |       ^~~
a.cc:42:13: error: 'nextStr' was not declared in this scope
   42 |       cmd = nextStr();
      |             ^~~~~~~
a.cc:44:9: error: 'arg' was not declared in this scope
   44 |         arg = nextStr();
      |         ^~~
a.cc:46:21: error: 'text' was not declared in this scope
   46 |           if (cur < text.size()) {
      |                     ^~~~
a.cc:50:24: error: 'text' was not declared in this scope
   50 |           while (cur < text.size() && isblank(text[cur])) {cur++;}
      |                        ^~~~
a.cc:50:39: error: 'isblank' was not declared in this scope
   50 |           while (cur < text.size() && isblank(text[cur])) {cur++;}
      |                                       ^~~~~~~
a.cc:51:24: error: 'text' was not declared in this scope
   51 |           while (cur < text.size() && !isblank(text[cur])) {cur++;}
      |                        ^~~~
a.cc:51:40: error: 'isblank' was not declared in this scope
   51 |           while (cur < text.size() && !isblank(text[cur])) {cur++;}
      |                                        ^~~~~~~
a.cc:54:9: error: 'arg' was not declared in this scope
   54 |         arg = nextStr();
      |         ^~~
a.cc:60:38: error: 'text' was not declared in this scope
   60 |           while (cur > 0 && !isblank(text[cur])) {cur--;}
      |                                      ^~~~
a.cc:60:30: error: 'isblank' was not declared in this scope
   60 |           while (cur > 0 && !isblank(text[cur])) {cur--;}
      |                              ^~~~~~~
a.cc:64:9: error: 'arg' was not declared in this scope
   64 |         arg = nextQuote();
      |         ^~~
a.cc:64:15: error: 'nextQuote' was not declared in this scope
   64 |         arg = nextQuote();
      |               ^~~~~~~~~
a.cc:65:9: error: 'text' was not declared in this scope
   65 |         text.insert(text.begin() + cur, arg.begin(), arg.end());
      |         ^~~~
a.cc:68:9: error: 'arg' was not declared in this scope
   68 |         arg = nextStr();
      |         ^~~
a.cc:70:21: error: 'text' was not declared in this scope
   70 |           if (cur < text.size()) {
      |                     ^~~~
a.cc:74:24: error: 'text' was not declared in this scope
   74 |           while (cur < text.size() && isblank(text[cur])) {
      |                        ^~~~
a.cc:74:39: error: 'isblank' was not declared in this scope
   74 |           while (cur < text.size() && isblank(text[cur])) {
      |                                       ^~~~~~~
a.cc:77:24: error: 'text' was not declared in this scope
   77 |           while (cur < text.size() && !isblank(text[cur])) {
      |                        ^~~~
a.cc:77:40: error: 'isblank' was not declared in this scope
   77 |           while (cur < text.size() && !isblank(text[cur])) {
      |                                        ^~~~~~~
a.cc:89:7: error: 'cout' was not declared in this scope
   89 |       cout << text[i];
      |       ^~~~
a.cc:89:15: error: 'text' was not declared in this scope
   89 |       cout << text[i];
      |               ^~~~
a.cc:91:5: error: 'cout' was not declared in this scope
   91 |     cout << "^";
      |     ^~~~
a.cc:92:27: error: 'text' was not declared in this scope
   92 |     for (int i = cur; i < text.size(); i++) {
      |                           ^~~~
a.cc:95:13: error: 'endl' was not declared in this scope
   95 |     cout << endl;
      |             ^~~~