Вопрос

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

Это было полезно?

Решение

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)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top