1

I'm reading C++ Primer 5th Edition when i came to this part. It's a code it provided that I have to use but I keep getting

error: no match for 'operator>>' (operand types are std::istream {aka std::basic_istream<char>} and Sales_item)

on line std::cin >> book;

I tried looking it up and rewriting the code but I can't get it to work so I need help to fix this problem.

#include <iostream>
#include "Sales_item.h"


int main()
{
    Sales_item book;
    // read ISBN, number of copes sold, and sales price
    std::cin >> book;
     // write ISBN, number of copies sold, total revenue, and average price
    std::cout << book << std::endl;
    return 0;
}
Praetorian
  • 106,671
  • 19
  • 240
  • 328
MrSkrifle
  • 11
  • 1

1 Answers1

2

The reason the operator is undefined is because operators work for specific types. Your type that you created, Sales_item, does not have that operator - unless you overloaded it to work for your specific type. See this question on Operator Overloading for more info.

Community
  • 1
  • 1
Ricky Mutschlechner
  • 4,291
  • 2
  • 31
  • 36