Hello.

How to create a file in C ++ and, for example, write a value in it, and after executing the program (say, there is a certain cycle) - the answer will appear in another file? That is, we enter data into the 1st file, execute the program, and the answer will be different. Thank you in advance. )

    2 answers 2

    Taking into account the fact that the question is tagged with a C++ tag, I will answer as it is done in C++ , and not in C

    Suppose you have a file with the contents of "25".

     #include <fstream> int main(int argc, char* argv[]) { std::ifstream input("input.in"); int number; input >> number; number += 45; std::ofstream output("output.out"); output << number; } 

    In this case, the output file output.out will be written 70 , that is ( 25 + 45 ).

    • 2 Kotik_khokhet_kusat, and why clauses for main ()? - user12324

    One of the options is described in the question: Working with files .

    The second option is to use I / O streams from the iostream standard library. Read about it at cplusplus.com .