我一直得到“libc ++ abi.dylib:以std :: invalid_argument:stoi:no conversion”的未捕获异常终止,最后用于“Total”计算。请建议具体更正。不知道如何纠正它。
int main() {
vector<Record> records; //Vector of type Record to hold each "line"
from the input file
string database;
/**
* Puts each line of the input file into the records vector
*/
string line;
string department;
string item_code;
int quanity;
double cost;
while(!ifs.eof() && ifs.is_open()) {
records.push_back(newRecord(ifs));
}
ifs.close(); //Close the stream
sort(records.begin(),records.end(), sortByItem_code);
stable_sort(records.begin(),records.end(), sortByDepartment);
custom mycustom =custom(records);
vector<Record> customRecords = mycustom.customRecords(true);
ofstream output("/Users/ziyingyu/Downloads/new_" + database);
string newifs;
cout<<fixed;
cout<<setprecision(2);
std::string::size_type sz;
output.open("/Users/ziyingyu/Downloads/new_" + database);
for (int i = 0; i < customRecords.size(); ++i)
{
/**
*go through each record of our clean records file
*/
output << i << "," << customRecords[i]<<endl;
cout << i << "," << customRecords[i]<<endl;
}
output.close();
output.open("/Users/ziyingyu/Downloads/new_" + database);
for(int i = 0; i < customRecords.size(); i++)
{
cout<<left<<setw(15)<<customRecords[i].department;
cout<<left<<setw(17)<<customRecords[i].item_code;
cout<<left<<setw(13)<<customRecords[i].quantity;
cout<<left<<setw(15)<<customRecords[i].cost;
cout<<left<<setw(15)
<<double(std::stoi(customRecords[i].quantity,
&sz)*std::stod(customRecords[i].cost, &sz))<<endl;
cout<<endl;
}
return 0;
}