16,551
社区成员
发帖
与我相关
我的任务
分享
#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); //这个函数并没有用类名调用,所以不是类中的方法,那它是
//是什么呢?难道不是类的成员函数吗,在哪里定义的呢?
cout << "you entered: " << str << endl;
cout << "length of string in charr after input:\n"
<< strlen(charr) << endl;
cout << "length of string in str after input: "
<< str.size() << endl;
return 0;
}