Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<string>
  4. #include<fstream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. struct student {
  10. int course;
  11. string sex;
  12. };
  13.  
  14.  
  15. int main()
  16. {
  17. ifstream File("C:\\Users\\Paul Maul\\Desktop\\file.txt");
  18. if (!File.is_open())
  19. {
  20. cout << "FILE NOT FOUND!";
  21. }
  22. else
  23. {
  24. int CoS=0;
  25. int Chars=0;
  26.  
  27. while (!File.eof())
  28. {
  29. char temp;
  30. File.get(temp);
  31. Chars++;
  32. if (temp == ';')
  33. {
  34. CoS++;
  35. }
  36.  
  37. }
  38. File.clear();
  39. File.seekg(0);
  40.  
  41.  
  42. char *Mass = new char[Chars];
  43.  
  44. for (int i = 0;!File.eof(); i++)
  45. {
  46. char temp;
  47. File.get(temp);
  48. Mass[i] = temp;
  49. }
  50.  
  51. string*tokMass = new string[4*CoS];
  52. student *Arr = new student[CoS];
  53. char*p = strtok(Mass, ";,");
  54. for (int i = 0; i < (4 * CoS); i++)
  55. {
  56. tokMass[i] = p;
  57. p = strtok(NULL, ";,");
  58. }
  59.  
  60. for (int j = 3, int i = 0; i < CoS; i++,j=j+4)
  61. {
  62. Arr[i].course = atoi(tokMass[j].c_str());
  63.  
  64. }
  65. for (int j = 4, int i = 0; i < CoS; j = j + 4)
  66. {
  67. Arr[i].sex = tokMass[j];
  68. }
  69. cout << Arr[2].course << endl;
  70. cout << Arr[3].sex << endl;
  71.  
  72.  
  73. for (int i = 0; i < (4 * CoS); i++)
  74. {
  75. cout << tokMass[i] << endl;
  76. }
  77.  
  78. }
  79. system("pause");
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement