x2311

Untitled

Jun 8th, 2022
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. //структура
  9. struct City{
  10.     string nameCity = "";
  11.     string region = "";
  12. };
  13. //path - путь к файлу
  14. void read_file(queue<City> &q, string path){
  15.     //Створюємо 3 черги для міст України
  16.     queue<City> kirovograd;
  17.     queue<City> Kyiv;
  18.     queue<City> Lviv;
  19.     //откриваем
  20.     ifstream info_students(path);
  21.    
  22.     string line;
  23.     City student;
  24.     stringstream ss;
  25.     //читаем и записуем в 3 черги
  26.     while(getline(info_students, line)){
  27.         ss << line;
  28.         ss >> student.nameCity;
  29.         ss >> student.region;
  30.         if(student.region == "Kirovograd"){
  31.             kirovograd.push(student);
  32.         }
  33.         else if(student.region == "Kyiv"){
  34.             Kyiv.push(student);
  35.         }
  36.         else{
  37.             Lviv.push(student);
  38.         }
  39.         ss.clear();
  40.     }
  41.     //вывод! kirovograd
  42.     while(!kirovograd.empty()){
  43.         q.push(kirovograd.front());
  44.         kirovograd.pop();
  45.     }
  46.     //вывод! Kyiv
  47.     while(!Kyiv.empty()){
  48.         q.push(Kyiv.front());
  49.         Kyiv.pop();
  50.     }
  51.     //вывод! Lviv
  52.     while(!Lviv.empty()){
  53.         q.push(Lviv.front());
  54.         Lviv.pop();
  55.     }
  56. }
  57. void print_queue(queue<City> q){
  58.     while(!q.empty()){
  59.         cout << "Name City : " << q.front().nameCity << endl
  60.              << "Region : " << q.front().region << endl << endl;
  61.         q.pop();
  62.     }
  63. }
  64.  
  65. int main()
  66. {
  67.     queue<City> students_info;
  68.     read_file(students_info, "..\\tess.txt");
  69.     //вывод всего
  70.     print_queue(students_info);
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment