c++ - Can not read text file with Qt 5 -


i wrote simple code open plain text file qt 5's qfile seen below;

// main.cpp #include <iostream> using std::endl; using std::cout;  #include <qcoreapplication> #include <qfile> #include <qiodevice>  int main(int argc, char *argv[]) {     qcoreapplication a(argc, argv);      qfile plainfile("plain.txt");      if(plainfile.open(qiodevice::readonly | qiodevice::text))     {         cout << "file opened successfull" << endl;         plainfile.close();     }     else{         cout << "could not open file." << endl;     }     return a.exec(); } 

the output when compiled , run "could not open file". wrong?

probably because plain.txt not exist in current working directory or in path. make sure file in working directory or pass absolute path qfile.

also see qfile::exists returns.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -