有代码不理解,求大佬帮忙!
程序代码:
#include <iostream> #include <string> #include <cstring> 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:\n"; getline(cin, str); 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; return 0; }
为什么这一段
cout << "Length of string in charr before input: "
<< strlen(charr) << endl;
结果是
Length of string in charr before input: 3
求大佬帮忙解释一下