Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- int main(int argc, char *argv[])
- {
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- link:
- std::string path = "file.txt";
- std::fstream fs;
- fs.open(path, /*запись*/ std::fstream::in | /*чтение*/ std::fstream::out | std::fstream ::app);
- if (fs.is_open())
- {
- int value;
- std::cout
- << "[1] Запись в файл" << std::endl;
- std::cout << "[2] Чтение из файла" << std::endl;
- std::cout << "1/2: ";
- std::cin >> value;
- std::string inputWord;
- if (value == 1)
- {
- int inputWord;
- std::cout << "Введите число: ";
- std::cin >> inputWord;
- fs << "\n";
- fs << inputWord;
- std::cout << "Сохранено!" << std::endl;
- }
- if (value == 2)
- {
- std::cout << "Текст файла: " << std::endl;
- while (!fs.eof())
- {
- inputWord = "";
- fs >> inputWord;
- std::cout << inputWord;
- }
- }
- goto link;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement