print the output to a txt file

how do i print this output to a text file instead of console window.i got this code also from this site. i do not want to change the function. only the output print to a txt file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  std::string next_file_name()
{
    static std::string prefix = "frame" ;
    static std::string suffix = ".png" ;
    
    static const int ub = 100 ; 
    static int n = 0 ;

    return prefix + std::to_string( n++ % ub + 1 ) + suffix ; // for 1 to hunfred
}

int main()
{
    for( int i = 0 ; i < 10 ; ++i )
        std::cout << "file name: " << next_file_name() << '\n' ;
}
Hello dsblaster,

At some point in the program you will have to set up a file stream and open a file to use for output.

FYI in the function "next_file_name" "n" could exceed 100. This could be a potential problem.

Hope that helps,

Andy
Topic archived. No new replies allowed.