Advertisement
vertexofvortex

Untitled

Oct 28th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a, b = 2;
  8. setlocale(LC_ALL, "ru");
  9.  
  10. string path = "file.txt";
  11. ofstream fout;
  12. fout.open(path);
  13.  
  14. if (!fout.is_open()) {
  15. cout << "Ошибка открытия файла" << endl;
  16. }
  17. else {
  18. for (int i = 0; i < 10; i++) {
  19. cout << "Введите число" << endl;
  20. cin >> a;
  21. fout << a;
  22. fout << "\n";
  23. }
  24.  
  25. string str;
  26. ifstream fin;
  27. fin.open(path);
  28.  
  29. while (!fin.eof()) {
  30. getline(fin, str);
  31. cout << str << endl;
  32.  
  33. if (str[str.length() - 1] == b) {
  34. int count = 0;
  35. count++;
  36. cout << "Count = " << count << endl;
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement