So I have been working on this mess for hours and I have no clue what I am doing wrong. I am trying to open this text file(the text file is there), but it just will not open for some reason. Am i doing something wrong here?
int main()
{
ifstream inData;
ofstream outData;
string item=string();
int cost=int();
int units=int();
int total=int();
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"\tInventory Report For Malik Anderson International Hardware"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"ITEM NUMBER OF UNITS UNIT COST($) TOTAL VALUE($)"<<endl;
cout<<"________________________________________________________________________________"<<endl;
inData.open("inventory.txt");
if (!inData)
{
cout << "Unable to open file inventory.txt";
exit(1); // if data is not found, call system to stop
}
if (inData.is_open())
{
while(!inData.eof())
{
total=units*cost; //stating what equals to total
inData.ignore(1,'\n');
inData>> left >> item >> " " >> right >> " " >> units >> " " >> cost >> " " >> total;
}
}
this line is wrong inData>> left >> item >> " " >> right >> " " >> units >> " " >> cost >> " " >> total; should look like this inData >> item >> units >> cost >> total I'm assuming that total is in the file and not something you have to calculate after the data is input.
I commented that line out and it worked fine for me. The file path you are using will only work if the txt file is saved in same folder as your project.
Thanks for the tip about the code tags. And yes, the txt file is in my project folder but it still won't freakin open. I even directed it to the desktop and it still would not work.