Hi I'm new to computer programming. 'Im just needing to learn some basic c++ for a larger project. So if someone wouldn't mind guiding me through some basics on i/o streams. I need to able to open a .txt file saved on my c drive and be able to count certain words in the file. So far Im just trying to figure out how to open a text file.
This is what I have:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
cout << myfile << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
however, when I run it "0x22fec4" continues to display constantly until I terminate it.
any ideas? Thanks.