Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- struct student {
- int course;
- string sex;
- };
- int main()
- {
- ifstream File("C:\\Users\\Paul Maul\\Desktop\\file.txt");
- if (!File.is_open())
- {
- cout << "FILE NOT FOUND!";
- }
- else
- {
- int CoS=0;
- int Chars=0;
- while (!File.eof())
- {
- char temp;
- File.get(temp);
- Chars++;
- if (temp == ';')
- {
- CoS++;
- }
- }
- File.clear();
- File.seekg(0);
- char *Mass = new char[Chars];
- for (int i = 0;!File.eof(); i++)
- {
- char temp;
- File.get(temp);
- Mass[i] = temp;
- }
- string*tokMass = new string[4*CoS];
- student *Arr = new student[CoS];
- char*p = strtok(Mass, ";,");
- for (int i = 0; i < (4 * CoS); i++)
- {
- tokMass[i] = p;
- p = strtok(NULL, ";,");
- }
- for (int j = 3, int i = 0; i < CoS; i++,j=j+4)
- {
- Arr[i].course = atoi(tokMass[j].c_str());
- }
- for (int j = 4, int i = 0; i < CoS; j = j + 4)
- {
- Arr[i].sex = tokMass[j];
- }
- cout << Arr[2].course << endl;
- cout << Arr[3].sex << endl;
- for (int i = 0; i < (4 * CoS); i++)
- {
- cout << tokMass[i] << endl;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement