Error when i do not include string header file in c++

六月ゝ 毕业季﹏ 提交于 2019-12-18 09:40:54

问题


#include<iostream>
#include<string>

using namespace std;
void main(){
string str="abc";
cout<<str;
system("pause");
}

If i do not include string header file then there is an error at << in line cout<

I thought the error will be at line where str is defined.


回答1:


Standard library headers can include other standard library headers, even if not specified in the standard. So it may be that with your implementation, the iostream header includes some parts of the string header, so that std::string is available but std::operator<<(std::basic_ostream<...>&, const std::basic_string<...>&); is not.



来源:https://stackoverflow.com/questions/20937474/error-when-i-do-not-include-string-header-file-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!