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
|
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <fstream>
#include <sstream>
#include "books.h"
using namespace std;
int main()
{
string line;
ifstream input("books.txt");
while(getline(input, line))
{
stringstream strStream(line);
string id, title, author, category, copies;
// Read tokens in this line one by one
getline(strStream, id, '|');
getline(strStream, title, '|');
getline(strStream, author, '|');
getline(strStream, category, '|');
getline(strStream, copies, '|');
// We need to convert the number of copies, and may be ID, to integers
int idNum, copiesNum;
stringstream idConverter(id);
idConverter >> idNum;
stringstream copiesConverter(copies);
copiesConverter >> copiesNum;
cout << idNum << ", " << title << ", " << author << ", " << category << ", " << copiesNum << endl;
}
system("pause");
return 0;
}
|