You may combine two approaches :-)
First you get the whole line with getline, and then consider that line a source of std::istringstream (which essentially is a usual istream) and split the input into words).
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
int main(void) {
std::vector<std::vector<std::string> > lines;
std::string line;
while ( std::getline(std::cin, line) ) {
if ( !line.empty() ) {
std::vector<std::string> words;
std::string word;
std::istringstream is(line);
while (is >> word)
words.push_back(word);
lines.push_back(words);
}
}
std::cout << "The word at line 3, pos 2 is \"" << lines[2][1] << '"' << std::endl;
return 0;
}
which gives me the following:
abc def gdf qwe asd zxc qaz wsx edc The word at line 3, pos 2 is "wsx"