smutnyjoe

cpp matura Adam

Nov 28th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. void wypisz(vector<int>& x){
  9.     for (int i : x)
  10.         cout << i << " ";
  11.  
  12.     cout << endl;
  13. }
  14.  
  15. void sortuj(vector<int> &a) {
  16.  
  17.     for (int i = 5; i >= 0; i--)
  18.         for (int j = 1; j <= i; j++ )
  19.             if (a[j-1] > a[j]) {
  20.                 int tmp = a[j];
  21.                 a[j] = a[j-1];
  22.                 a[j-1] = tmp;
  23.             }
  24.  
  25. }
  26.  
  27.  
  28.  
  29. int main() {
  30.     vector<int> a  = {7, 5, 1, 2, 3, 6};
  31.  
  32.     string linia;
  33.     vector<int> v;
  34.     vector<vector<int>> obraz; //TODO pomyslec
  35.  
  36.     ifstream plik;
  37.     plik.open("../dane.txt");
  38.     if( !plik.good() ){
  39.         cout << "Nie można wczytać pliku" << endl;
  40.         return -1;
  41.     }
  42.  
  43.     while(!plik.eof()){
  44.         getline(plik, linia);
  45.  
  46.         stringstream iss (linia);
  47.         int number;
  48.         while ( iss >> number)
  49.             v.push_back(number);
  50.     }
  51.  
  52.     wypisz(v);
  53.  
  54.  
  55.     //TODO: zrobic wektor wektorow int i wczytywac kolejne linie
  56.  
  57.  
  58.     return 0;
  59. }
Add Comment
Please, Sign In to add comment