getline(ss,token, ' '); price = stoi(token); getline(ss,token, ' '); markup = stoi(token); getline(ss,token, ' '); quantity[0]=stoi(token); getline(ss,token, ' '); quantity[1]=stoi(token); getline(ss,token, '\n'); quantity[2]=stoi(token); float profit = price*(markup/100.0)*(quantity[0]+quantity[1]+quantity[2]); cout<
It seems like the 'stoi' function doesn't work for my version of C++.
Can you fix it for me?
-I can not update my C++ to a newer version
Code:
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
int main()
{
ifstream f("Inventory.txt");
string line, name;
float price;
int markup,quantity[3];
bool flag=true;
cout<<setw(30)<<"Name"<<setw(20)<<"Total Profit"<<endl;
while(getline(f, line))
{
if(flag==true)
{
if(line=="END")
break;
else
{
name = line;
}
flag=false;
}
else
{
stringstream ss(line);
string token;
getline(ss,token, ' ');
price = stoi(token);
getline(ss,token, ' ');
markup = stoi(token);
getline(ss,token, ' ');
quantity[0]=stoi(token);
getline(ss,token, ' ');
quantity[1]=stoi(token);
getline(ss,token, '\n');
quantity[2]=stoi(token);
float profit = price*(markup/100.0)*(quantity[0]+quantity[1]+quantity[2]);
cout<<setw(30)<<name<<setw(10)<<" ";
printf("%.2f\n",profit);
flag=true;
}
}
}
Error Message: error: 'stoi' was not declared in this scope
price=stoi(token);
Step by step
Solved in 2 steps