How can I input something that is already output on the console screen. For example, if the code is:
cout << 2 + 2 << endl;
the console screen will show:
4
How can I read this 4 from the OUTPUT screen into a variable?
PS. - I know I can just save it into a variable within the code and not go to the output screen at all, but for some reason I HAVE to read input which is already printed on the screen by the computer.
You cannot read what is on the screen. At least one cannot do this in a portable manner.
What you can do is redirect where std::cout goes -- send it to a stream that buffers the output (maybe in a stringstream) and also writes it to STDOUT. You can then read back anything that was written to std::cout.