CppStreamOutOperator

(C++) Stream out operator <<

This operator is used most comming using the std::cout stream:

  1. 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:

  1. include <iostream>
  2. 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.

  1. include <iostream>
  2. include <vector>
#include <string> int main() { std::string s = "Hello"; std::cout << s; }


Questions



last edited (December 24, 2006) by bilderbikkel

Back to the page