Facebook
From Agacia, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 215
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <cstdlib>
  6. #include <list>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. int main()
  13. {
  14.     vector< vector <int> > lista_nast;
  15.     string wiersz;
  16.     int wierzcholek;
  17.     int iter = -1;
  18.     unsigned i, j;
  19.  
  20.     fstream plik;
  21.     plik.open("C:\\Users\\Agata\\Desktop\\plik.txt", ios::in);
  22.  
  23.     while(!plik.eof())
  24.     {
  25.         //cout<<"wszedlem"<<endl;
  26.         getline(plik, wiersz);
  27.         if(wiersz == ";")
  28.         {
  29.            // cout<<"if"<<endl;
  30.             lista_nast.push_back(vector<int> ());
  31.             iter++;
  32.  
  33.         }
  34.         else
  35.         {
  36.             //cout<<"else"<<endl;
  37.             wierzcholek = atoi(wiersz.c_str());
  38.             lista_nast[iter].push_back(wierzcholek);
  39.         }
  40.     }
  41.     plik.close();
  42.  
  43.     cout<<endl<<"Lista nastepnikow: "<<endl;
  44.     for( i=0; i<lista_nast.size(); i++)
  45.     {
  46.         for( j=0; j<lista_nast.size(); j++)
  47.         {
  48.             cout<<lista_nast[i][j]<<" ";
  49.         }
  50.         cout<<endl;
  51.     }
  52.     return 0;
  53. }
  54.