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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Students{
string name, surname;
string q1, q2, q3, q4, q5;
};
bool readStudents(ifstream &fromStream, Students &a) {
getline(fromStream, a.name, ',');
getline(fromStream, a.surname, ',');
getline(fromStream, a.q1, ',');
getline(fromStream, a.q2, ',');
getline(fromStream, a.q3, ',');
getline(fromStream, a.q4, ',');
getline(fromStream, a.q5);
return true;
}
bool writeStudents(ostream &toStream, Students a) {
toStream << a.name << "\t" << a.surname << "\t"
<< a.q1 << "\t" << a.q2 << "\t" << a.q3 <<
"\t" << a.q4 << "\t" << a.q5 << endl;
return true;
}
int main()
{
string name = "input.csv";
string name2 = "output.csv";
ifstream iF(name.c_str());
if (iF == NULL) {
cout << "CSV file open error" << endl;
return -1;
}
Students students;
while (!iF.eof()) {
readStudents(iF, students);
writeStudents(cout, students);
}
iF.close();
return 0;
}
|