Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <queue>
- using namespace std;
- //структура
- struct City{
- string nameCity = "";
- string region = "";
- };
- //path - путь к файлу
- void read_file(queue<City> &q, string path){
- //Створюємо 3 черги для міст України
- queue<City> kirovograd;
- queue<City> Kyiv;
- queue<City> Lviv;
- //откриваем
- ifstream info_students(path);
- string line;
- City student;
- stringstream ss;
- //читаем и записуем в 3 черги
- while(getline(info_students, line)){
- ss << line;
- ss >> student.nameCity;
- ss >> student.region;
- if(student.region == "Kirovograd"){
- kirovograd.push(student);
- }
- else if(student.region == "Kyiv"){
- Kyiv.push(student);
- }
- else{
- Lviv.push(student);
- }
- ss.clear();
- }
- //вывод! kirovograd
- while(!kirovograd.empty()){
- q.push(kirovograd.front());
- kirovograd.pop();
- }
- //вывод! Kyiv
- while(!Kyiv.empty()){
- q.push(Kyiv.front());
- Kyiv.pop();
- }
- //вывод! Lviv
- while(!Lviv.empty()){
- q.push(Lviv.front());
- Lviv.pop();
- }
- }
- void print_queue(queue<City> q){
- while(!q.empty()){
- cout << "Name City : " << q.front().nameCity << endl
- << "Region : " << q.front().region << endl << endl;
- q.pop();
- }
- }
- int main()
- {
- queue<City> students_info;
- read_file(students_info, "..\\tess.txt");
- //вывод всего
- print_queue(students_info);
- }
Advertisement
Add Comment
Please, Sign In to add comment