|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ifstream in("text.txt");
string s,line;
int i,num=0,length;
while(getline(in,line))
{
s+=line+"\n";
}
length=strlen(s);
for(i=0;i<length;i++)
{
if(s[i]==' ')
num+=1;
}
cout<<s;
cout<<"the number of the word is:"<<num<<endl;
cout<<strlen(s)<<endl;
return 1;
}
结果出错:
D:\Program Files\Microsoft Visual Studio\MyProjects\todd\todd.cpp(24) : error C2664: 'strlen' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
why?????
|
|