【发布时间】:2016-07-25 14:39:35
【问题描述】:
代码如下,字符串库已注释,但程序运行良好
#include<iostream>
//#include<string> // the string library has been commented
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0; i<n; i++){
string str;
int num = 0;
cin>>str;
int len = str.length(); //the function length is used here!
for (int j =0; j< len; j++){
if (str[j] >='0' && str[j] <='9')
num ++;
}
cout<<num<<endl;
}
return 0;
}
【问题讨论】:
-
不包括库你怎么能使用
string? -
This shows that it doesn't work。如果你想使用
std::string,那么#include就可以了。如果你的编译器碰巧在编译器的#includes集合中的某个地方包含了在您的代码中使用。