I'm having a problem with ifstream in C++. I'm using Xcode. I don't get how to get a simple use of ifstream to work. I'm trying to use the code below:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char buffer[256];
ifstream myfile("testtext");
while (!myfile.eof() )
{
myfile.getline (buffer,100);
cout << buffer << endl;
}
return 0;
}
I don't see anything wrong with that code. I made a text file using Text Wrangler (testtext) and put it in the project's folder. When I build n go, it just outputs an infinite amount of blank space and keeps going until I hit the "stop task" button. I must be doing something wrong since it's doing that instead of showing the one line of text I wrote. Could someone help me out with this?