Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. int _tmain(int argc, _TCHAR* argv[])
  12. {
  13. ifstream inFile;
  14. ofstream outFile;
  15.  
  16. //inFile.open("plates.txt"); FOR IFSTREAM: ([file name], [access mode (ios::read, ios::write, ios::app)]) ios::app adds data onto file, without it, the file will be overwritten
  17. outFile.open("plates.txt", ios::app);
  18.  
  19. string number;
  20. string reading;
  21.  
  22. do
  23. {
  24. cout << "Enter a license plate number: ";
  25. cin >> number;
  26. if (number != "0")
  27. {
  28. outFile << number << endl;
  29. }
  30. }
  31. while (number != "0"); //Use "" double quotations when working with cstrings
  32.  
  33. outFile.close();
  34.  
  35. inFile.open("plates.txt");
  36.  
  37. if (!inFile)
  38. {
  39. cout << "Error opening file!" << endl;
  40. }
  41.  
  42. cout << "\nYou entered the following license plate numbers:" << endl;
  43.  
  44. while (!inFile.eof())
  45. {
  46. inFile >> reading;
  47. cout << reading << endl;
  48. }
  49.  
  50. system("pause");
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement