1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct marketType
{
public:
string market;
string name;
string street;
string city;
string state;
string country;
};
void readMarkets (ofstream &outfile,ifstream &infile, marketType marketArray[]);
void finalOutput(ofstream &outfile, marketType marketArray[]);
void openFile2(ofstream &outfile,ifstream &infile);
//======================================================================
int main()
{
ifstream infile; // set a name for ifstream
ofstream outfile; // set a name for ofstream
marketType MyMarket; // set a name for MarketType
marketType marketArray[10]; // make an array to hold the market information
outfile.open ("report.txt"); //open the final output file
//============== FUNCTIONS ===================
openFile2(outfile, infile);
readMarkets (outfile, infile, marketArray);
finalOutput(outfile, marketArray );
//========= END FUNCTIONS ====================
system("pause");
return 0;
}
//=======================================================================
void readMarkets (ofstream &outfile,ifstream &infile, marketType marketArray[]) //==============
{
int i = 0;
while(!infile.eof() && i < 10)
{
getline(infile,marketArray[i].market, '\t');
getline(infile,marketArray[i].name, '\t');
getline(infile,marketArray[i].street, '\t');
getline(infile,marketArray[i].city, '\t');
getline(infile,marketArray[i].state, '\t');
getline(infile,marketArray[i].country, '\t');
i++;
}
infile.close();
}
void finalOutput(ofstream &outfile, marketType marketArray[])
{
outfile << marketArray[0].market <<endl;
outfile << marketArray[0].name <<endl;
outfile << marketArray[0].street <<endl;
outfile << marketArray[0].city <<endl;
outfile << marketArray[0].state <<endl;
outfile << marketArray[0].country <<endl;
}
void openFile2(ofstream &outfile,ifstream &infile) //=================
{
infile.open("markets.txt");
if(!infile)
{
cout << "Unable to open input book file!" << endl ;
system ("pause");
}
}
| |