Read from console

Hi guys :)
I want to read the console output in a string. Is there a easy way to do this ?
Something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main(){
	cout<<"blablup";
	string fromConsole=getFromConsole();		//some magic function
	cout<<fromConsole;				//this should print blablup

	cin.sync();
	cin.ignore();
	return 0;
}
Last edited on
If you are looking for a way to ask user for input and send it to console, the Fransje's suggestion is perfect.
If, however, you need a way to read a text from what is already printed on the console window, there is a bit bigger challenge ahead of you. I am not sure is there is really any C++ specific funtion to actually read from console, because console is an output device with implementation details dependent on specific platform. But you magic function can be e.g. Windows specific ReadConsoleOutput function which your can do some reading about here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684965(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684206(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms685032(v=vs.85).aspx
Last edited on
Thanks JockX,I ment the second task.I will take a look at those links :)
Topic archived. No new replies allowed.