Input file problem

I am using NetBeans and i just want to open a file but it doesn't work.
I have got my main.cpp and next to it my file.
The output is "Failed".
Thank you for helping a beginner.

#include <iostream>
#include <fstream>

int main ()
{
using namespace std;

ifstream instream;

instream.open("ex1.rtf");

if(instream.fail( )) {
cout << "Failed ";
exit(1);
}




}
Where is your executable located? That's what matters, not your .cpp file. Make sure your resource is in the same place as your executable, or provide an absolute path for the file.

Edit: Also, if NetBeans default settings are anything like CodeBlocks, it might be trying to get resources from where the project file is, not the executable, so check if your IDE has a "resource path"/"working directory" option or something.
Last edited on
Topic archived. No new replies allowed.