[Solved] Getting a C++ program to write to a file [closed]


It sounds like you’re saying you’re printing numbers to stdout and they’re going off the screen. Since you’re using C++ you can replace cout in your output instructions with an ofstream (output file stream) like so:

#include <fstream>
// ...
    ofstream outFile("myNums.txt");
    // ...
    outFile << myNum;

An easier way if you already have the program done is to just redirect the output. This means when you run your program add > myNums.txt to the end. So for instance:

./myProg > myNums.txt

solved Getting a C++ program to write to a file [closed]