the task:
It is required to write in C ++ a program for entering text information from the keyboard into a file on the C drive:
the program opens writes the previously entered text. But I need to enter my text into the console from the keyboard and then save to the C drive:
#include <iostream> using namespace std; int main() { setlocale(0,""); // включаем кириллицу в консоли char * fileName = "C:\\example.txt"; // Путь к файлу для записи FILE * file = fopen(fileName, "w"); if (file) // если есть доступ к файлу, { char * str = "I Like The Coding!"; // инициализируем строку bool result = fputs(str, file); // и записываем ее в файл if (!result) // если запись произошла успешно cout << "Строка в файл успешно записана!" << endl; // выводим сообщение } else cout << "Нет доступа к файлу!" << endl; fclose(file); return 0; }