Advertisement
Eksekk

Column

May 18th, 2021
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. int main(int argc, char* argv[])
  7. {
  8.     std::fstream plik(argv[2], std::ios::in);
  9.     std::string linia;
  10.     std::stringstream ss;
  11.     int n = atoi(argv[1]);
  12.     while (getline(plik, linia))
  13.     {
  14.         ss.clear();
  15.         ss.str("");
  16.         ss << linia;
  17.         std::string wyraz;
  18.         int i = 0;
  19.         while (ss >> wyraz)
  20.         {
  21.             ++i;
  22.             if (i == n)
  23.             {
  24.                 break;
  25.             }
  26.         }
  27.         if (i != n)
  28.         {
  29.             std::cout << '\n';
  30.             continue;
  31.         }
  32.         std::cout << wyraz << '\n';
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement