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

请C++高手指教,该怎么解决

2012-02-27 
请C++高手指教最近刚学C++,在调用string类的时候出错,例如下面的程序:#includeiostream.h#includestrin

请C++高手指教
最近刚学C++,在调用string类的时候出错,例如下面的程序:
#include   <iostream.h>
#include   <string.h>

void   mian()
{string   p1= "hello ";
cout < <p1 < <endl;
}

出错信息为:
Compiling...
test.cpp
f:\test\test.cpp(5)   :   error   C2065:   'string '   :   undeclared   identifier
f:\test\test.cpp(5)   :   error   C2146:   syntax   error   :   missing   '; '   before   identifier   'p1 '
f:\test\test.cpp(5)   :   error   C2065:   'p1 '   :   undeclared   identifier
f:\test\test.cpp(5)   :   error   C2440:   '= '   :   cannot   convert   from   'char   [6] '   to   'int '
                This   conversion   requires   a   reinterpret_cast,   a   C-style   cast   or   function-style   cast
Error   executing   cl.exe.

test.obj   -   4   error(s),   0   warning(s)

应该是没有加载string头文件的缘故,但明明已经写了include语句,请大家指教下。

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

using namespace std;

热点排行