std::ios_base is private

Hi, I'm trying to pas ostream object as a parameter to my function,
and I get this error.

here is my function
1
2
3
4
5
6
7
8
9
10
11
12
void printTask(int op1, int op2, int len, char operation, std::ostream& os)
{
    os << endl << "  " << setw(len) << op1 << endl;
    os << operation << " " << setw(len) << op2 << endl;
    os << "-------------" << endl;
    os << "  ";
    for(int i = 0; i < len; i++)
    {
        os << "?";
    }
    os << endl;
}


and how I call it
1
2
3
4
printTask(op1, op2, answer_lengts, '+', file);
printTask(op1, op2, answer_lengts, '+', cout);
//first 4 parameters are OK, first 3 are int's and 4th is char. 'file' is of type fstream
//fstream file("output.txt", ios::out); 


Can anyone offer some help please?


EDIT:
I know that ostream can't have copy constructor, so that is why I'm trying to pass by reference...

I even tried to go with default parameter:
void printTask(int op1, int op2, int len, char operation, ostream& os = cout)

Same thing
Last edited on
¿Can you please paste the error message verbatim?


Also, provide a minimal code example that does reproduce your issue.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <iomanip>
#include <fstream>

void printTask(int op1, int op2, int len, char operation, std::ostream& os)
{
	using namespace std;
    os << endl << "  " << setw(len) << op1 << endl;
    os << operation << " " << setw(len) << op2 << endl;
    os << "-------------" << endl;
    os << "  ";
    for(int i = 0; i < len; i++)
    {
        os << "?";
    }
    os << endl;
}

int main(){
	using namespace std;
	fstream file("output.txt", ios::out); 
	printTask(1, 2, 3, '-', file);
}
builds fine
Topic archived. No new replies allowed.