In the original file, total. Isbn() = = trans. Isbn() will report an error in vscode, “unable to match the call error”
compile. CPP: 12:37: error: no match for call to ‘(STD:: _cxx11:: String
{aka STD:: _cxx11:: basic_string}) ()’
if (total. Isbn() = = trans. Isbn())
solution: remove the brackets after. Isbn() and change the primitive sentence to
if (total.isbn==trans.isbn)
The reason is that ISBN should be a parameter value rather than a method, or it may be caused by my environment. It is for reference only.
#include <iostream>
#include"Sales_item.h"
int main(){
Sales_item total;
if (std::cin>>total)
{Sales_item trans;
while (std::cin>>trans)
{
if (total.isbn()==trans.isbn())
total+=trans;
else
{
std::cout<<total<<std::endl;
total=trans;
}
}
std::cout<<total<<std::endl;
}
else{
std::cerr<<"NO Data?!"<<std::endl;
return -1;
}
return 0;
}