string line, word;// will hold a line and word from input, rectively while (getline(cin, line)) { // read a line from the input into line // do per-line processing istringstream stream(line); // bind to stream to the line we read while (stream >> word) { // read a word from line // do per-word processing } }