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

C++primer简单有关问题

2012-02-27 
C++primer简单问题1:std::string s(hello world)std::cout s std::endl和2:std::cout hello wo

C++primer简单问题
1:
std::string s("hello world");
std::cout << s << std::endl;

2:
std::cout "hello world" <<std::endl;

1不能编译通过,2能通过;为什么1不能编译通过?

编译环境vs2008

[解决办法]
stl的string类没有重载<<操作符,cout继承的<<操作符里面也没有操作stl::string类型的
而2中参数类型是 const char* 类型的,cout的<<操作符有此类型的重载

热点排行