Question

Here's the code.

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, const char * argv[])
{
    ifstream myfile;
    myfile.open("numbers.txt");

    if (myfile.is_open()){
        cout <<" okay to proceed" << endl;
    } else {
        cout<< "error finding file" <<endl;
    }
}

The file is as named, exactly and in the same folder as the program.

What am I doing wrong? The is_open() check is failing >_<

Edit: Solved. Found the working directory under product - scheme - options

Was it helpful?

Solution

Plenty of reasons: 1. No r permission (no access to read file) 2. "numbers.txt" is in some other directory, not one application was started ... Use full path in myfile.open("FULLPATH/numbers.txt"); just to be sure you are open correct file. Than check access rights (OS dependent)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top