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?
Opening a .txt file using codelite?
-
- CodeLite Curious
- Posts: 1
- Joined: Wed Nov 13, 2013 6:53 am
- Genuine User: Yes
- IDE Question: C++
- Contact:
- 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?
No...vincentt wrote:Could it be because my code can't see the .txt file through Codelite?
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