Why are you opening your file with both ios::in
and ios::out
flags (it seems that you're only writing to this file)? ios::in
will require an existing file:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
fstream f1("test1.out", ios::binary | ios::in | ios::out);
if(!f1)
{
cout << "test1 failed\n";
}
else
{
cout << "test1 succeded\n";
}
fstream f2("test2.out", ios::binary | ios::out);
if(!f2)
{
cout << "test 2 failed\n";
}
else
{
cout << "test2 succeded\n";
}
}
output:
burgos@olivia ~/Desktop/test $ ./a.out
test1 failed
test2 succeded
Maybe you want to use ios::app
?