Here is an example program that shows you how to do it using a string stream (without having to use Ctrl-Z or Ctrl-D). There might be a better way, but this sems to do what you want.
Code:
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
int main()
{
// Get input from user.
std::string inputLine;
std::getline(std::cin, inputLine);
// Create a stream to parse the line.
std::istringstream lineStream(inputLine);
// Loop through each word in the stream.
std::vector<std::string> sentence;
while (!lineStream.eof())
{
std::string word;
lineStream >> word;
sentence.push_back(word);
}
// Output one word per line.
std::vector<std::string>::const_iterator iterWord = sentence.begin();
std::vector<std::string>::const_iterator iterEnd = sentence.end();
for (; iterWord != iterEnd; ++iterWord)
{
std::cout << *iterWord << std::endl;
}
}
Note that if you are running VC++ 6.0 you will have to fix the bug in getline or this won't work well. Just go to http://www.dinkumware.com/vc_fixes.html and scroll down to the <string> fix.