#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
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: " << endl;
getline(cin,str);
cout << "You entered: " << str << endl;
//cout << "Length of string in charr after input: " << sizeof(charr) << endl;
//sizeof() 秀出的是矩陣的大小
cout << "Length of string in charr after input: " << strlen(charr) << endl;
cout << "Length of string in str after input: " << str.size() << endl;
system("pause");
return 0;
}
沒有留言:
張貼留言