Files
python/TangDou/AcWing/EulerPath/scanfReadString.cpp

26 lines
472 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
/*
测试用例:
abc
*/
const int N = 110;
int main() {
string a;
// scanf读入string的方法
a.resize(N); //需要预先分配空间
scanf("%s", &a[0]);
// printf输出string的方法
printf("%s\n", a.c_str());
//正确的字符串的长度:3
cout << strlen(a.c_str()) << endl;
//错误的字符串长度:110
cout << a.size() << endl;
return 0;
}