sorting string in my file

hey guys hi,
I want to sort my items using Array, would anyone help me out please.


#include <iostream>
#include <iomanip>
#include <fstream>
#include <limits>


int main()
{
int totalItems=0;
int totalPrice=0;
std::ifstream inputFile("AAAAAA.txt"); //reading a file

if(!inputFile) //check if the file exits
{
std::cout <<"failed to open"<< std::endl;
}

else
{
std::cout <<"\n"<< std::setfill('=')<< std::setw(65);//forming a header for the program

std::cout<<"\n="<< std::setfill(' ')<<std::setw(42);

std::cout<<"FARMER\'S MARKET INVENTORY"<< std::setw(20)<<"=";

std::cout<<"\n"<< std:: setfill('=') <<std::setw(64)<<" "<<std::endl;
std:: string farmName=" ";
int countOfItem=0, countTotal=0;
std::string item=" ";
float itemPrice =0, grandTotal = 0, newItem=0;// seting values

while (!(getline(inputFile,farmName,',').eof()))
{
inputFile>>countOfItem;
inputFile>>item;
inputFile>>itemPrice;
double total = countOfItem*itemPrice;
std::cout<<farmName<<" :"<<countOfItem<<" "<<item<<"@ "<<itemPrice<<" totaling $"<<total<<std::endl;
totalItems=totalItems+countOfItem;
totalPrice=totalPrice+total;
}
std::cout<<"\n"<<"Grand total: "<<totalItems<<"items"<<" totaling $:"<<totalPrice<<"\n";// output the total vaule
return 0;
}


}


Last edited on
Can you show us the contents of the file "AAAAAA.txt"?
Topic archived. No new replies allowed.