It's been a while since I've worked with File I/O in C++ (and just C++ in general) but I recently decided to use it to make a small console project for a friend. My issue is that I'm having some issues with a string array and File I/O (I'm not sure which is causing the problem). My code is as follows (ReadPSWDS is an ifstream):
int i = 0;
string str[200];
ReadPSWDS.clear();
ReadPSWDS.open("myPasswords.DoNotOpen");
if(ReadPSWDS.is_open())
{
while(!ReadPSWDS.eof())
{
getline(ReadPSWDS, str[i]); //Store the line
if(str[i].length()<1 || str[i] == "")
{
//Ignore the line if it's nothing
}
else
{
i++; //Move onto the next 'cell' in the array
}
}
}
ReadPSWDS.close();
My issue is that on testing this out, the string array would appear to be empty (and on writing all those lines to a file, the file is empty as expected). Why is the string array empty and not filled with the appropriate lines of the text file?
Regards,
Joe