2
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

struct twoVals
{
        int x;
    double y;
} number;

int main()
{
    number.x = 10;
    number.y = 20;

twoVals vals;
cout << vals << endl;

return 0;

}

Line 19: error: no match for 'operator<<' in 'std::cout << vals' compilation terminated due to -Wfatal-errors.

That is the error I get. How do I fix this? Is there anything else wrong with my code? Give examples.

Javaturtle
  • 329
  • 1
  • 2
  • 13
  • 3
    Well, there is no `std::ostream& operator<<(std::ostream&, const twoVals&)`. Easy as that. You need to define one yourself, or simply show both members: `cout << vals.x << " " << vals.y;`. However, it seems that you just started C++ coming from C. This is a good time to grab a [C++ book](http://stackoverflow.com/q/388242/1139697) before you start developing bad habits. – Zeta Jul 02 '15 at 04:42
  • Thanks, Add as a answer next time so I can upvote. – Javaturtle Jul 02 '15 at 04:44
  • There's probably at least one duplicate of this, see the related links ;) – Zeta Jul 02 '15 at 04:44

0 Answers0