Advertisement
kijato

file_to_vector

Mar 2nd, 2018
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <unordered_map>
  8. #include <set>
  9. #include <list>
  10.  
  11. #include <sys/stat.h>
  12.  
  13. using namespace std;
  14.  
  15. int main(int argc, char *argv[], char *env[])
  16. {
  17.     string file_name;
  18.     if(argc==2)
  19.     file_name = string(argv[1]);
  20.     else
  21.     file_name = "s:\\big_text_file.dat";
  22.  
  23.     ifstream f(file_name);
  24.     if (!f)
  25.     {
  26.         cerr<<"Nem sikerült megnyitni a \""<<file_name<<"\" fájlt...!\n";
  27.         return 1;
  28.     }
  29.  
  30.     string row;
  31.     vector<string> rows;
  32.     int i=0,rows_length=0;
  33.     while(getline(f,row))
  34.     {
  35.         i++;
  36.         rows_length+=row.length()+2;
  37.         rows.push_back(row);
  38.         /*
  39.         cerr.setf(ios::right);
  40.         cerr<<"i="<<i<<"\t"
  41.         <<"string -> addr / size / összes.  : "<<&row <<" / "<<row.size()<<" / "<<rows_length<<"\t"
  42.         <<"vector -> addr / size / capacity : "<<&rows<<" / "<<rows.size()<<" / "<<rows.capacity()<<" ["<<rows.size()*100/rows.capacity()<<"%]\t\r";
  43.         */
  44.     }
  45.  
  46.     cout << endl
  47.          << "sorok...            "<<endl
  48.          << "   száma:           "<<i<<endl
  49.          << "   hossza összesen: "<<rows_length<<" darab karakter"<<endl<<endl;
  50.     cout << "vektor...           "<<endl
  51.          << "   méret:           "<<rows.size()<<" darab"<<endl
  52.          << "   kapacitás:       "<<rows.capacity()<<" darab"<<endl
  53.          //<< "   max.méret: "<<rows.max_size()<<endl
  54.          <<endl;
  55.  
  56.     cout <<"shrink..."<<endl;
  57.     rows.shrink_to_fit();
  58.  
  59.     cout << "vektor...           "<<endl
  60.          << "   méret:           "<<rows.size()<<" darab"<<endl
  61.          << "   kapacitás:       "<<rows.capacity()<<" darab"<<endl
  62.          //<< "   max.méret: "<<rows.max_size()<<endl
  63.          <<endl;
  64.  
  65.     struct stat s;
  66.     stat(file_name.c_str(),&s);
  67.     cout << "fájl méret:   "<<s.st_size<<" byte ("<<s.st_size/1024<<" Kbyte)"<<endl<<endl;
  68.  
  69.     cout << endl; system("\"tasklist /fi \"imagename eq file_to_vector.exe\"");
  70.  
  71.     cout << endl; system("\"powershell -c \"get-process file_to_vector\"");
  72.  
  73.     // cout << endl; system('ps -C file_to_vector -O rss | awk \'{count++;sum+=$2}; END {count--;print"Count =",count;print"Sum =",sum/1024,"MB";};\'');
  74.  
  75.     cin.get();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement