c++ - getline() not opening text file -


hi using codeblocks 13.12 on osx.

i trying open following .txt file

line 1
line 2
line 3

my code just:

#include <iostream> #include <fstream> #include <string>  using namespace std;  int main() {     cout<<'\n';     std::string line;     ifstream myfile("textex.txt");     if(myfile.is_open())         cout << "file open";     else         cout << "file not open";      cout<<'\n';     return 0; } 

i have included file in project folder , have tried linking , compiling it.

when run code, displays"file not open" , i'm not sure why? i'm new c++, can please explain why isn't working?

instead of

    ifstream myfile("textex.txt"); 

try

    ifstream myfile;     myfile.open("/users/name/code/textex.txt"); // use full path 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -