-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4_10.cpp
More file actions
30 lines (28 loc) · 795 Bytes
/
4_10.cpp
File metadata and controls
30 lines (28 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//strtype4.cpp
#include<iostream>
#include<string>
#include<cstring>
int main()
{
using namespace std;
char charr[20];
string str;
cout << "Length of string in charr before input: "
<< strlen(charr) << endl;
cout << "Length of string in str before input: "
<< str.size() << endl;
cout << "Enter a line of text: \n";
cin.getline(charr, 20); //指出最大长度
cout << "You entered: " << charr << endl;
cout << "Enter another line of text:\n";
getline(cin, str); //此时cin是一个参数,不需指定长度
cout << "You entered: " << str << endl;
cout<< "Length of string in charr after input: "
<< strlen(charr) << endl;
cout << "Length of string in str after input: "
<< str.size() << endl;
cin.get();
cin.get();
cin.get();
return 0;
}