Language: C++

using namespace std;
#include <iostream>
#include <vector>
#include <string.h>
#include <string>

#define REP(i, n) for(int i=0; i<n; i++)

typedef vector<int> VI;

int T, N;
string text;
string cmd;
string tmp;

void execute(string& text, string cmd)
{
	if(cmd == "forward char"){
		REP(i, text.size())
		{
			if(text[i] == '^')
			{
				if(i != text.size()-1)
				{
					text[i] = text[i+1];
					text[i+1] = '^';
					break;
				}
			}
		}
	}
	else if(cmd =="forward word")
	{
		int iCaret = -1;
		REP(i, text.size())
		{
			if(text[i] == '^')
			{
				iCaret = i;
				continue;
			}

			if(text[i] == ' ' && iCaret != -1)
			{
				if(i != 0)
				{
					if(text[i-1] == ' ' || text[i-1] == '^')
					{
						continue;
					}
				}

				text.insert(text.begin()+i, '^');
				text.erase(text.begin()+iCaret);
				break;
			}

			if(i == text.size()-1 && iCaret != -1)
			{
				text.insert(text.end(), '^');
				text.erase(text.begin()+iCaret);
				break;
			}
		}
	}
	else if(cmd == "backward char")
	{
		REP(i, text.size())
		{
			if(text[i] == '^')
			{
				if(i != 0)
				{
					text[i] = text[i-1];
					text[i-1] = '^';
				}
			}
		}
	}
	else if(cmd == "backward word")
	{
		int iCaret = -1;
		for(int i=text.size()-1; i>=0; i--)
		{
			if(text[i] == '^')
			{
				iCaret = i;
				continue;
			}

			if(text[i] == ' ' && iCaret != -1)
			{
				if(i != text.size()-1)
				{
					if(text[i+1] == ' ' || text[i+1] == '^')
					{
						continue;
					}
				}

				text.erase(text.begin() + iCaret);
				text.insert(text.begin() + i, '^');
				break;
			}

			if(i == 0 && iCaret != -1)
			{
				text.erase(text.begin() + iCaret);
				text.insert(text.begin(), '^');
				break;
			}
		}
	}
	else if(cmd == "delete char")
	{
		REP(i, text.size())
		{
			if(text[i] == '^')
			{
				if(i != text.size()-1)
				{
					text.erase(text.begin() + i+1);
				}
			}
		}
	}
	else if(cmd == "delete word")
	{
		int first = 0;
		int last = 0;
		REP(i, text.size())
		{
			if(text[i] == '^')
			{
			<	first = i;
			}
			
			if((text[i] == ' ' || i == text.size()-1) && first != 0)
			{
				if(i != 0)
				{
					if(text[i-1] == ' ' || text[i-1] == ' ')
					{
						continue;
					}
				}

				text.erase(text.begin()+first+1, text.begin()+i);
			}
		}
	}
	else
	{
		bool is_insert = true;
		string str_insert = "insert";
		REP(i, str_insert.size())
		{
			if(str_insert[i] != cmd[i])
			{
				is_insert = false;
				break;
			}
		}

		if(is_insert)
		{
			string word_insert = string(cmd, str_insert.size()+2, cmd.size()-str_insert.size()-3);
			std::copy(cmd.begin()+str_insert.size()+2, cmd.end()-1, word_insert.begin());
			cout << word_insert << endl;
			
			REP(i, text.size())
			{
				if(text[i] == '^')
				{
					text.insert(i, word_insert);
					break;
				}
			}
		}
	}
}

int main()
{
	getline(cin, tmp);
	T = atoi(tmp.c_str());

	REP(t, T)
	{
		getline(cin, text);
		text = "^" + text;
		cout << text << endl;

		getline(cin, tmp);
		N = atoi(tmp.c_str());
		REP(n, N)
		{
			getline(cin, cmd);
			execute(text, cmd);
			cout << text << endl;
		}
	}
}

Compiler output:
a.cc: In function 'void execute(std::string&, std::string)':
a.cc:135:25: error: expected primary-expression before '<' token
  135 |                         <       first = i;
      |                         ^