谁能帮我看看这个简单小程序
//求字符串的长度
#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;
}