Hi HashCode.Ru.

Here is the code, but I don’t know how to make the file start when the program is started, and what’s written in the program and what’s written in the file will appear?

#include "stdafx.h" #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { setlocale(LC_ALL, "rus"); ofstream fout("data_types.txt", ios_base::out | ios_base::trunc); if (!fout.is_open()) // если файл не был открыт { cout << "Файл не может быть открыт или создан\n"; return 1; } getchar(); fout.close(); cout << "Данные успешно записаны в файл data_types.txt\n"; system("pause"); return 0; } 
  • one
    > system("pause"); Oh. - drdaeman
  • one
    @drdaeman, and what's wrong with that? - AseN
  • one
    To begin with, this is a useless crutch. MSVS, if the subsystem console is set up and started without debugging, will ask itself before closing the window. And let's end with the fact that cin.get() , instead of launching a separate interpreter process and pause in it, has not been canceled. - drdaeman

1 answer 1

If "something", then after checking the opening of the file, you can enter

 string chto_to; getline (cin, chto_to); fout << chto_to << endl;