问题
#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