nht_cntt

BTTuan5 tmp

May 4th, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. std::vector<std::string> ReadParagraph(FILE *pFile);
  6.  
  7. int main()
  8. {
  9.     std::vector<std::string> DoanVan;
  10.  
  11.     std::string str(""), tmp, str1, str2;
  12.  
  13.     char cStr[255];
  14.     FILE *pFile;
  15.  
  16.     pFile = fopen("In.txt", "rt");
  17.    
  18.     if ( !pFile ) std::cout << "File Error \n";
  19.  
  20.     DoanVan = ReadParagraph(pFile);
  21.  
  22.     std::cout << "\n";
  23.    
  24.  
  25.     for (int i = 0; i < DoanVan.size(); ++i)
  26.     {
  27.         std::cout << DoanVan[i];
  28.         system("pause >> NULL");
  29.     }
  30.  
  31.  
  32.     fclose (pFile);
  33.    
  34.    
  35.    
  36.     return 0;
  37. }
  38.  
  39. std::vector<std::string> ReadParagraph(FILE *pFile)
  40. {
  41.     char Buff[255];
  42.     int n = 1, i = 0;
  43.     std::vector<std::string> Para(n); // Paragraph
  44.  
  45.     while ( !feof(pFile) )
  46.     {
  47.         fgets(Buff, 255, pFile);
  48.  
  49.         Para[i] = Para[i] + Buff;
  50.  
  51.         if (  strchr(Buff, '\n') )
  52.         {
  53.             if ( Para[i] == "\n" )
  54.             {
  55.                 Para[i] = "";
  56.             }
  57.             else
  58.             {
  59.                 ++n;
  60.                 Para.resize(n);
  61.                 ++i;
  62.             }
  63.         }
  64.     }
  65.     return Para;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment