C++ examples for Language Basics:Console
Use cin to read char array as string
#include <iostream> using namespace std; #include <iomanip> int main()//w ww. j ava 2 s .c o m { char first[20], last[20]; cout << "What is your first name? "; cin >> first; cout << "What is your last name? "; cin >> last; cout << "\n\n"; // Prints two blank lines. cout << "In a phone book, your name would look like this:\n"; cout << last << ", " << first; return 0; }