(C++) Need help resolving Output file error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>

// accept an output stream (which may be a file stream) to the function
std::ostream& ShowProgramHeader( std::ostream& stm )
{
    // use the stream which was passed in the function
    return stm << "the program header here (whatever it is)\n" ;
}

// accept an output stream (which may be a file stream) to the function
// use the stream which was passed in the function
int SquareMachine( std::ostream& stm ) ;

int main()
{
    const char file_name[] = "sTable.out" ;

    std::ofstream fout(file_name) ; // out|trunc is the default

    if( fout.is_open() ) // not fout.is.open()
    {
        ShowProgramHeader(fout) ; // pass the stream to the function

        // ...

        const int result = SquareMachine(fout) ; // pass the stream to the function

        // rest of the program

    }

    else
    {
        std::cerr << "failed to open output file " << file_name << '\n' ;
        return 1 ;
    }
}

Repost bot just posting anything just so they can put their spammy link somewhere in the post.

https://stackoverflow.com/questions/44878386/c-need-help-resolving-output-file-error

Please check 1-posters
- do they have spammy links in their profile
- do their questions read like a tutorial rather than a question
Topic archived. No new replies allowed.