Advertisement
35657

Untitled

Apr 20th, 2024
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. struct student {
  9.     string last_name;
  10.     string first_name;
  11.     int number;
  12. };
  13.  
  14. int main() {
  15.    
  16.     SetConsoleCP(1251);
  17.     SetConsoleOutputCP(1251);
  18.  
  19.     vector<student> students;
  20.  
  21.     ifstream fin;
  22.     fin.open("C:/Users/PC/Documents/student.txt");
  23.  
  24.     if (!fin.is_open()) {
  25.         cout << "Ошибка открытия файла" << endl;
  26.     }
  27.     else {
  28.         student temp;
  29.         for (int i = 0; i < 3; i++) {
  30.             fin >> temp.last_name >> temp.first_name >> temp.number;
  31.             students.push_back(temp);
  32.         }
  33.  
  34.         for (const student& st : students) {
  35.             cout << st.last_name << " " << st.first_name << " " << st.number << endl;
  36.         }
  37.  
  38.         fin.close();
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement