Page 1 of 1

Opening a .txt file using codelite?

Posted: Wed Nov 13, 2013 6:58 am
by vincentt
Have some really basic code, but can't seem to open a .txt file. The file is in the same directory as my .cpp and .h files (in the project folder) on my computer.

Here is the code:

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

int main() {
string tmpString;
ifstream myFile ("myText.txt");
cout << myFile.is_open() << endl;
if (myFile.is_open()) {
while (getline(myFile, tmpString)) {
cout << tmpString << endl;
}
myFile.close();
}
else cout << "Unable to open file." << endl;
return 0;
}

Could it be because my code can't see the .txt file through Codelite?

Re: Opening a .txt file using codelite?

Posted: Wed Nov 13, 2013 10:31 am
by eranif
vincentt wrote:Could it be because my code can't see the .txt file through Codelite?
No...

It probably because your working directory is not where you think it is
codelite will place the executable in an intermediate folder e.g. Debug, Release etc ( unless instructed otherwise )

So make sure that your .txt files are placed next to the executable and not next to the source files

Eran