previous | start | next

## Processing Text Input

- When processing text input, is the input structured as a sequence of characters, words, or lines?
- To input a sequence of word, use the loop

  >     string word;
  >     while (cin >> word)
  >     {
  >        process word
  >     }

- `cin >> word` has the same value as `cin` - it is the same test as `!cin.fail()`.
- To process input one line at a time, use the `getline` function.

  >     string line;
  >     while (getline(cin, line))
  >     {
  >        process line
  >     }

- As above, the `getline` function returns `cin`, so you can test that `cin` hasn't yet failed.
- To process input character by character, use the loop

  >     char ch;
  >     while (cin.get(ch))
  >     {
  >        process ch
  >     }

previous | start | next