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

来帮初学者看一小下下哈

2012-03-01 
来帮菜鸟看一小下下哈!#includeiostream#includestringusingstd::coutusingstd::endlintmain(){stri

来帮菜鸟看一小下下哈!
#include   <iostream>
#include   <string>
using   std::cout;
using   std::endl;


int   main()
{
string   st( "The   expense   of   spirit\n ");
cout < < "The   size   of "   < <   st < < "is " < <st.size()
< < "characters,including   the   newline " < <endl;
return   0;
}


编译错误提示:

--------------------Configuration:   Text2   -   Win32   Debug--------------------
Compiling...
Text2.cpp
C:\Program   Files\我的文档\我的视频\Text2.cpp(9)   :   error   C2065:   'string '   :   undeclared   identifier
C:\Program   Files\我的文档\我的视频\Text2.cpp(9)   :   error   C2146:   syntax   error   :   missing   '; '   before   identifier   'st '
C:\Program   Files\我的文档\我的视频\Text2.cpp(9)   :   error   C2065:   'st '   :   undeclared   identifier
C:\Program   Files\我的文档\我的视频\Text2.cpp(10)   :   error   C2228:   left   of   '.size '   must   have   class/struct/union   type
执行   cl.exe   时出错.

Text2.exe   -   1   error(s),   0   warning(s)


why?how   can   i   do?

[解决办法]
using std::cout;
using std::endl;

把这两句换成
using namespace std;

热点排行