C++primer简单有关问题
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的<<操作符有此类型的重载
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的<<操作符有此类型的重载