首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-03-02 
谁能帮我看看这个简单小程序//求字符串的长度#includeiostream#includestringusingnamespacestdintma

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

热点排行