Outputting String Variables Using cout

This example outputs the word correctly, without the garbage characters. It does so because cout looks for the NULL character and stops output at that point:
void main(void)
{
  char word[10];

  cout << "Enter a string ";
  cin >> word;

  cout << word;  
}

Output:
Celsius
char word[7] = {'C','e','l','s','i','u','s'};
cout << word;

Output: (potential)
CelsiusÉî!? Q?Éî    ! Yæ?SX   LASTDRIVEL
MULTITRACKDRIVPARMP?STACKSKJ \æ\æ;æ? `?` ` `æ
Previous page
Next page

Back to Lesson 12 Index
Back to Outline