C++ getting error when outputing text into file with ifstream

So I am writing some stuff to a file and I'm getting this error when:
1
2
3
int x = 10;
ifstream data ("data.txt", ifstream::out);
data << x << "\n";

The error is:
Invalid operands to binary expression ('ifstream' (aka basic_ifstream'<char>') and 'int')
Why are you trying to output with an ifstream?
Either use an fstream with ios::out or use an ofstream.
Topic archived. No new replies allowed.