Unable to clear the Controller Screen

The controller text is notoriously difficult to manage.
Each command needs to be at least 50ms apart, no matter what.
Essentially, the controller polls the robot every 50ms and the robot returns the latest command.
If you call clear but right away call something else, the clear will be ignored.

I know you are delaying in that snippet, but there might be somewhere else that causes the clear command to be overridden.
It is possible opcontrol gets restarted when it exits. Not sure, but it is worth a try to delay after the clear command.

I have had problems with the joystick, but as soon as I made a wrapper class that acted like a buffer for my write commands, that ensures a command is only sent every 50ms, it worked smoothly. I then expanded it to support two controllers and rumble commands. Everything is possible if you properly manage the timing, but that is tough to do without abstracting stuff. It is difficult to properly do the timing in arbitrary user code.

Anyways, try this code:

void opcontrol() {
  pros::delay(1000);
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  pros::delay(50);
  master.set_text(0, 0, "Example");
  pros::delay(50);
  master.clear();
  pros::delay(50);
  pros::delay(5000000); //wait forever
}