error: no match for 'operator<<' in 'outfile << std::setw(10)'

I'm not sure what this error means...can anyone help me out?
31|error: no match for 'operator<<' in 'outfile << std::setw(10)

Here is my code:
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
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

ifstream infile;
ifstream outfile;

int main()
{
    int a, b, c = 0;

    infile.open("triangle2.txt");
    if(!infile)
    {
        cout << "Error opening input file." << endl;
        return 1;
    }

    outfile.open("answers.out");
    if(!outfile)
    {
        cout << "Error opening output file." << endl;
        return 1;
    }

    infile >> a >> b >> c;
    while(infile)
    {
        outfile << setw(10) << a << " " << b << " " << c << endl;
        cout << setw(10) << a << " " << b << " " << c << endl;
    }
    return 0;

}
It means that the compiler does not know what to do when you use a << operator with an object of type ifstream.

Given that an ifstream is for inputtng data, it seems odd that you named it outfile. Perhaps you meant outfile to be an object of type ofstream? So that you can use to to output data.
Last edited on
Topic archived. No new replies allowed.