variable = expression
totalPeople = 4;
totalCost = adultCost + otherCost;
cout <<
expression;
cout
is a stream.
cout << "The name is " << name << endl;
endl
is a special value
'\n'
for a new line.
endl
string firstName, lastName, fullName; firstName = "Dan"; lastName = "Bennett"; fullName = firstName + " " + lastName;
word = "\"Hello\" World";
cin
is an input stream.
string word; cin >> word;
word
getline
is a function
string phrase; getline(cin, phrase);
string word, phrase; cout << "Enter a word: "; cin >> word; cout << "Enter a phrase: "; getline(cin, phrase);
hello↩ This is a phrase ↩
hello
would be stored in word.
string word, phrase; cout << "Enter a word: "; cin >> word; cin.ignore(100,'\n'); cout << "Enter a phrase: "; getline(cin, phrase);
ignore
will skip the next 100 characters or until it sees a newline character.