title: C++ How to display/print a string object? cout << int works, cout << string not
body: <p>I ran into an issue google could not solve. Why is that cout works for an int object but not a string object in the following program? </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  class MyClass {
      string val;
  public:
      //Normal constructor.
      MyClass(string i) {
          val= i;
          cout &lt;&lt; "Inside normal constructor\n";
      }
      //Copy constructor 
      MyClass(const MyClass &amp;o) {
          val = o.val;
          cout &lt;&lt; "Inside copy constructor.\n";
      }
      string getval() {return val; }
  };
  void display(MyClass ob)
  {
      cout &lt;&lt; ob.getval() &lt;&lt; endl;    //works for int but not strings
  }
  int main()
  {
      MyClass a("Hello");
      display(a);
      return 0;
  }
  </code></pre>