#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;
int main()
{
IOS
string s = "1";
cout << s.size() - 2;
return 0;
}
输出结果为
18446744073709551615
s.size()返回的是一个无符号类型的,s.size() - 2也会被计算成一个正数,然后wa了
用的时候注意先转化为int
string s = "1";
int len = s.size() - 2;
cout << len;
或者
string s = "1";
for(int i = 0; i + 2 < s.size(); i ++)
{
}