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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
#define MAX_BOOKS 500
struct bookType
{
public:
string item_name;
string listing_id;
string seller_sku;
string price;
string quantity;
string open_date;
string item_note;
string item_condition;
string product_id;
string market;
string book_header_line;
};
string headings[10];
//======================================================================
int main()
{
ifstream infile;
ofstream outfile;
bookType MyBooks;
bookType bookArray[MAX_BOOKS];
void getHeadings(ofstream& outfile,istream& infile, string headings[10]);
void ReadBooks(ofstream& outfile,ifstream &infile, bookType bookArray[MAX_BOOKS]);
outfile.open ("report.txt");
infile.open("books.txt");
if(!infile)
{
cout << "Unable to open input book file!" << endl ;
system ("pause");
return 1;
}
cout << "Processing Data" << endl;
getHeadings(outfile , infile, &headings[10]);
ReadBooks(outfile, infile, &bookArray[MAX_BOOKS]);
for (int i = 0; i < 100; i++) //<-------------------------------- This is giving
{ //<------------------------------------------------------------ me a ACCESS
cout << bookArray[i].market << endl;//<------------------------ WRITE LOCATION
} //<------------------------------------------------------------ VIOLATION ERROR.
system("pause");
return 0;
}
//=======================================================================
void getHeadings(ofstream& outfile,istream& infile,string headings[10])
{
for (int i = 0; i < 10; i++)
{
infile >> headings[i];
cout << headings[i] << endl;
}
outfile << headings[0]
<< setw(headings[3].size() + 60)<< headings[3]
<< setw(headings[4].size() + 7) << headings[4]
<< setw(headings[8].size() + 4) << headings[8]
<< setw(headings[8].size() + 3) << headings[9] <<endl;
for(int i = 0; i < 175; i++)
{
outfile << "_";
}
outfile << endl;
}
void ReadBooks(ofstream &outfile,ifstream &infile, bookType bookArray[MAX_BOOKS])
{
int i = 0;
while(!infile.eof() && i < MAX_BOOKS)
{
getline(infile,bookArray[i].item_name, '\t');
getline(infile,bookArray[i].listing_id, '\t');
getline(infile,bookArray[i].seller_sku, '\t');
getline(infile,bookArray[i].price, '\t');
getline(infile,bookArray[i].quantity, '\t');
getline(infile,bookArray[i].open_date, '\t');
getline(infile,bookArray[i].item_note, '\t');
getline(infile,bookArray[i].item_condition, '\t');
getline(infile,bookArray[i].product_id, '\t');
getline(infile,bookArray[i].market, '\n');
//tPrice = atof(MyBooks.price.c_str());
outfile << bookArray[i].item_name << setw(100 - bookArray[i].item_name.size()) << '\t'
<< bookArray[i].price << setw(10 - bookArray[i].price.size()) << '\t'
<< bookArray[i].quantity << '\t'
<< bookArray[i].product_id << '\t'
<< bookArray[i].market << endl;
i++;
}
}
|