#include <iostream>
#include <string>
#include <fstream>
using namespace Std;
const int money = 10000;
struct patrons
{
String name;
Double money;
};
int main ()
{Ifstream inFile;
Infile.open ("Demo6_9.txt");
if (!infile.is_open ())
{
cout<< "Could not open the file \" demo6_9\ "\ n";
cout<< "program terminating!\n";
Exit (Exit_failure);
}
int num;
infile>>num;
cout<< "The number of patrons is:" <<num<< "." <<endl;
Infile.get (); .//Read newline characters
String name;
int money;
Patrons *pt = new Patrons[num];
if (Infile.is_open ())
{
int i;
for (i=0;i<num;i++)
{
infile>>name;
infile>>money;
Pt[i].name = name;
Pt[i].money = money;
Getline (Infile,pt[i].name); Read one line of input
(Infile>>pt[i].money). get ();
}
int k=0;
cout<< "Grand Patrons:" <<endl;
for (i=0;i<num;i++)
if (Pt[i].money >= money)
{
cout<<pt[i].name<< "" <<pt[i].money<<endl;
k++;
}
if (k==0)
cout<< "none.\n";
cout<< "Patrons:" <<endl;
if (k==num)
cout<< "none.\n";
Else
{
for (i=0;i<num;i++)
if (Pt[i].money < money)
cout<<pt[i].name<< "" <<pt[i].money<<endl;
}
}
Infile.close ();
Delete [] pt;
System ("pause");
return 0;
}
This is my previous practice, you see, it should be helpful ~
My txt format is
4
Sam Stone
2000
Freida Flass
100500
Tammy Tubbs
5000
Rich Raptor
55000
As you said the column OK, the row is not sure, you can also use a method similar to CIN Read ~ Think of you cin how to use, Ifstream so use ~
Read TXT file in course design--c++