0

I'm trying to write a simple test program that would do:

echo Hello world! | myprogram.exe

And the output would be:

I heard: "Hello world!". Message length: 12 chars.
rsk82
  • 28,217
  • 50
  • 150
  • 240
  • @Mat: nothing, I even do not know where to begin, what function to use, there are many examples on the web but they seem very advanced, I thought that on a simple example it would be easier to understand what's going on. I'm very new to C++. – rsk82 May 13 '12 at 11:20
  • Then continue searching, use something "C++ read stdin" - lots of hits, including here and a basic I/O tutorial that contains all you need in one web page. – Mat May 13 '12 at 11:25
  • http://stackoverflow.com/questions/201992/how-to-read-until-eof-from-cin-in-c – rsk82 May 13 '12 at 12:29

2 Answers2

1

Use the input stream std::cin, declared in < iostream >. The exact usage depends on your needs, i.e. you'll need different functions for reading words, characters, whole lines or maybe even all input.

Pat
  • 1,726
  • 11
  • 18
0

I found, this is the function:

string readStdin() {
  stringstream ss;
  string line;
  while (getline(cin, line)) {
    ss << line << endl;
  }
  cin.clear();
  return ss.str();
}
rsk82
  • 28,217
  • 50
  • 150
  • 240