(C++) Stream out operator <<
This operator is used most comming using the std::cout stream:
- include <iostream>
int main()
{
std::cout << "Hello world" << std::endl;
return 0;
}
Compile error 'operator<<' not implemented in type 'ostream' for arguments of type 'std::string'
Caused by the following simple code:
- include <iostream>
- include <vector>
int main()
{
std::string s = "Hello";
std::cout << s;
}
The answer is to #include <string>, which contains the definition of the function lacking.
- include <iostream>
- include <vector>
#include <string>
int main()
{
std::string s = "Hello";
std::cout << s;
}
Questions