MIS 24053 Lecture Notes - Lecture 22: Delimiter, Anson Chan, C String Handling

13 views5 pages

Document Summary

Example 1 char message1[12] = "hello world"; cout << message1 << endl; message1: char message2[12]; cin >> message2; // type "hello" as input message2: The function getline can be used to read an entire line of input into a string variable. The first specifies the area into which the string is to be read. The second specifies the maximum number of characters, including the string delimiter. Example 3: getline char a_string[80]; cout << "enter some words in a string:\n"; cin. getline(a_string, 80); cout << a_string << \nend of output\n"; Example 4: getline example char a_string[5], e_string[80]; cout << "enter some words in a string:\n"; cin >> a_string; cin. getline (e_string, 9) ; cout << a_string << "#" << e_string. Example 5: getline example char lastname[30], firstname[30]; cout << "enter a name :\n"; cin. getline (lastname, sizeof(lastname), ","); cin. getline (firstname, sizeof(firstname)); cout << "here is the name you typed:\n |" << firstname << " " << lastname << "|\n";

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers