qtyj123 发表于 2014-6-9 13:05:23

为什么我的简单程序不能运行

#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==' ')

    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?????


页: [1]
查看完整版本: 为什么我的简单程序不能运行