I am doing the problem 1.22 in the book of C++ primer 5th edition. I want to read several Sales_item objects until I don't want to put in more. I don't know how to tell the terminal that I think it's time to end, I don't want to put in more.
I tried to type in "*" or any other thing which is not a Sales_item object. But the program never ends.
#include <iostream>
#include "Sales_item.h"
int main() {
Sales_item item;
while (std::cin >> item)
item += item;
std::cout << item << std::endl;
return 0;
}
I expect when I type something that is not a Sales_item object, I could get a sum-up Sales_item object and get out of the program.