You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
472 B
26 lines
472 B
#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;
|
|
}
|