Advertisement
Guest User

Untitled

a guest
Mar 5th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. // reading a text file
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string barcode;
  10.     ifstream myInputFile("input.txt");
  11.     ofstream myOutPutFile("test.txt", ofstream::out);
  12.  
  13.     int count = 1;
  14.     if (myInputFile.is_open())
  15.     {
  16.         while (getline(myInputFile, barcode, '*'))
  17.         {
  18.             barcode = barcode.substr(1, barcode.size() - 1);
  19.             cout << count << '=' << barcode << '\n';
  20.             myOutPutFile << count << '=' << barcode << '\n';
  21.             count++;
  22.         }
  23.         myInputFile.close();
  24.         myOutPutFile.close();
  25.     }
  26.  
  27.     else {
  28.         cout << "Unable to open input file";
  29.     }
  30.     std::cin.get();
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement