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
|
ifstream in;
stringstream ss;
map<int,index> inds;
in.open("ra2.txt");
int size;
string sizeString;
getline(in,sizeString,':');
ss << sizeString;
ss >> size;
ss.clear();
ss.str(string());
int personStart;
string psString;
getline(in,psString,':');
ss << psString;
ss >> personStart;
ss.clear();
ss.str(string());
while(in.tellg() < personStart){
int locationId;
string idString;
getline(in,idString,':');
ss << idString;
ss >> locationId;
ss.clear();
ss.str(string());
int startByte;
string sbString;
getline(in,sbString,':');
ss << sbString;
ss >> startByte;
ss.clear();
ss.str(string());
int indexSize;
string sizeString;
getline(in,sizeString,':');
ss << sizeString;
ss >> indexSize;
ss.clear();
ss.str(string());
index temp(startByte,indexSize);
temp.locationID = locationId;
inds[locationId] = temp;
}
for(map<int,index>::iterator it = inds.begin(); it != inds.end(); it++){
in.seekg(it->second.startByte);
int data1,data2;
string d1String,d2String;
ss.clear();
ss.str(string());
getline(in,d1String,':');
ss << d1String;
ss >> data1;
ss.clear();
ss.str(string());
getline(in,d2String,':');
ss << d2String;
ss >> data2;
ss.clear();
ss.str(string());
cout << "data 1: " << data1 << " data 2: " << data2 << endl;
}
int choice;
cout << "enter a number you want 1 or 2 " << endl;
cin >> choice;
if(choice < 1 || choice > inds.size()){
return 1;
}else{
in.seekg(inds[choice-1].startByte); // -1 because indexs start at 0
int d1,d2;
string s1,s2;
getline(in,s1,':');
ss << s1;
ss >> d1;
ss.clear();
ss.str(string());
getline(in,s2,':');
ss << s2;
ss >> d2;
ss.clear();
ss.str(string());
cout << "data 1 : " << d1 << "data 2 : " << d2 << endl;
}
|