Skip to content

Instantly share code, notes, and snippets.

@tinwritescode
Created December 27, 2019 06:13
Show Gist options
  • Save tinwritescode/5282abc57ded81622dfabed691c7e15f to your computer and use it in GitHub Desktop.
Save tinwritescode/5282abc57ded81622dfabed691c7e15f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Student {
int id{-1};
string name;
string gender;
double mark{ 0.0 };
};
void readFile(const string fileName, Student classA[], int n) {
ifstream f;
string str, tmp;
f.open(fileName);
if (f.is_open() == false) cout << "File khong ton tai.";
else {
while (!f.eof()) {
getline(f, str);
cout << str << endl;
classA[n].id = stoi(str.substr(0, 3));
classA[n].name = str.substr(4, str.find("(") - 4);
classA[n].gender = str.substr(str.find("(") + 1, str.find(")") - str.find("(") - 1);
classA[n].mark = stof(str.substr(str.find(")")+1));
n++;
}
}
f.close();
}
int main() {
int n = 0;
Student classA[100];
readFile("INPUT.TXT", classA, n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment