读书人

哪位高手能帮小弟我看看这个简单小程序

发布时间: 2012-03-02 14:40:29 作者: rapoo

谁能帮我看看这个简单小程序
//求字符串的长度
#include <iostream>
#include <string>

using namespace std;

int main()
{
string str = "this is a string "; //这一行不要改
int lenth=strlen(str);
cout < < "the lenth is " < <lenth;
return 0;
}

编译提示错误如下,怎么改才对啊?
C:\Documents and Settings\Text1.cpp(9) : 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
Error executing cl.exe.

[解决办法]
#include <iostream>
#include <string>

using namespace std;

int main()
{
string str = "this is a string "; //这一行不要改
int lenth=str.length();
cout < < "the lenth is " < <lenth;
return 0;
}

读书人网 >C++

热点推荐