This is probably a really silly question (as I'm only a beginner at this!), but I'm having major dramas with reading textfiles.
The thing is, I can get it to work, if I use the following code:
But what I want to do, is use a variable for the name of the textfile. I have a menu in which the user can select one of 9 textfiles. eg. if they select 1, then I assign fileName = "flush.txt" or
if they select 2, then I assign fileName = "FourKind.txt"; (Using a swtich statement).
So I have the code:
The error message I get when I try to compile is:
'no matching function for call to 'ifstream:pen(string &)' candidates are ifstream:pen(const char *, int, int)'
fileName I have declared as a global variable, but as a string.
Is this why I'm having all the dramas? If so, what am I meant to declare fileName as? I tried declaring it as a char array, but had even more dramas!!
Any help would be greatly appreciated!!
Also, before I go, what difference does it make if you add
using namespace std; into your code? I was told that you can't use cin or cout without it, but I don't put it it and I have no dramas using cin or cout.