Using cin to Input Strings

To input strings with cin, use the get() method:
char text[20];      // declare array of 20 chars
cin.get(text, 20);  // get 19 chars + NULL
If you really want to read 20 characters, you'll need to do this:
char text[21];      // declare array of 20 chars
cin.get(text, 21);  // get 20 chars + NULL
Previous page
Next page

Back to Lesson 12 Index
Back to Outline