Opening a .txt file using codelite?

General questions regarding the usage of CodeLite
vincentt
CodeLite Curious
Posts: 1
Joined: Wed Nov 13, 2013 6:53 am
Genuine User: Yes
IDE Question: C++
Contact:

Opening a .txt file using codelite?

Post 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?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Opening a .txt file using codelite?

Post 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
Make sure you have read the HOW TO POST thread
Post Reply