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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
//Items
const int items(2);
int inv[items];
string iteminfo[items][2];
//Test variables
int i, ii, iii;
//Reusable functions
void clrsc()
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
void blanks(int a)
{
for(i;i<=a;i++)cout << "\n";
}
//Files
ofstream ofile;
ifstream itemfile;
size_t semicolon;
size_t pos;
string line, line2, line3;
int linecount(0);
int itemsetup();
int main()
{
i = itemsetup();
if (i == 1)
{
cout << "Failed to load items. Application shall now exit. ";
system("PAUSE");
return 1;
}
system("PAUSE");
return 0;
}
int itemsetup()
{
itemfile.open("Items.txt");
//If file is open, read it.
if (itemfile.is_open())
{
//Count lines in the file so we know how many lines to read.
while(! itemfile.eof())
{
getline(itemfile,line);
linecount++;
}
itemfile.seekg(0);
for(i=1;i<=linecount;i++)
{
//Check the line is not excluded. A comma at beginning of line signifies to ignore line.
getline(itemfile,line);
semicolon = line.find(",");
if (semicolon != 0)
{
//Find which item to enter info for.
pos = line.find(",");
line2 = line.substr(pos);
line.erase(pos);
stringstream(line) >> ii;
//
line2.erase(0,2);
pos = line2.find(",");
line = line2.substr(pos);
line2.erase(pos);
iteminfo[ii][0] = line2;
cout << iteminfo[ii][0];
//
line.erase(0,2);
pos = line.find(",");
line2 = line.substr(pos);
line.erase(pos);
iteminfo[ii][1] = line;
//
line2.erase(0,2);
pos = line2.find(",");
line = line2.substr(pos);
line2.erase(pos);
iteminfo[ii][2] = line2;
//
line.erase(0,2);
pos = line.find(",");
line2 = line.substr(pos);
line.erase(pos);
iteminfo[ii][3] = line;
//
line2.erase(0,2);
pos = line2.find(",");
line = line2.substr(pos);
line2.erase(pos);
iteminfo[ii][4] = line2;
}
}
itemfile.close();
}
else
{
return 1; //If couldn't open return error message.
}
return 0;
}
|