ptrennum
asked on
Probelm with CStdioFile ReadString
I'm reading in a file line by line like this:
CString strLine;
while(!fUserList.ReadStrin g(strLine) )
{
arUsers.Add(strLine);
}
the file itself looks like this:
mark,p
trennum,t
yello,y
when it hits the while loop it crashes and gives me the error "An unknown error occured While accessing file" Not quite sure why this CStdioFile is giving me so many problems or why I'm getting that error.
PT
CString strLine;
while(!fUserList.ReadStrin
{
arUsers.Add(strLine);
}
the file itself looks like this:
mark,p
trennum,t
yello,y
when it hits the while loop it crashes and gives me the error "An unknown error occured While accessing file" Not quite sure why this CStdioFile is giving me so many problems or why I'm getting that error.
PT
ASKER
Start of loop and yes I am opening it,
fUsers.Open("C:\\UserID.in f", CFile::modeCreate || CFile::modeNoTruncate || CFile::modeRead, &e);
fUsers.Open("C:\\UserID.in
ptrennum,
What do you have a ! (not) condition for your while loop?
I don't think that belongs there.
Should be something like the following:
while(fUserList.ReadString (strLine))
{
arUsers.Add(strLine);
}
David Maisonave :-}
What do you have a ! (not) condition for your while loop?
I don't think that belongs there.
Should be something like the following:
while(fUserList.ReadString
{
arUsers.Add(strLine);
}
David Maisonave :-}
ptrennum,
> >fUsers.Open("C:\\UserID.i nf", CFile::modeCreate || CFile::modeNoTruncate
> >|| CFile::modeRead, &e);
Why are you using modeCreate in your open command to open a file for read access?
David Maisonave :-}
> >fUsers.Open("C:\\UserID.i
> >|| CFile::modeRead, &e);
Why are you using modeCreate in your open command to open a file for read access?
David Maisonave :-}
ASKER
Yes you are certainly right about that one,
However I am still getting the same crash if debugging it takes me into wincore.cpp
However I am still getting the same crash if debugging it takes me into wincore.cpp
ASKER
I am passing the file to this function:
GetListFromFile(CStdioFile &fUserList)
the call looks like this
if(!lstUsers.GetListFromFi le(fUsers) )
GetListFromFile(CStdioFile
the call looks like this
if(!lstUsers.GetListFromFi
ptrennum,
> >if(!lstUsers.GetListFromF ile(fUsers ))
Please post the full code for function GetListFromFile
David Maisonave :-}
> >if(!lstUsers.GetListFromF
Please post the full code for function GetListFromFile
David Maisonave :-}
ASKER
CString strLine;
while(fUserList.ReadString (strLine))
{
arUsers.Add(strLine);
}
if(arUsers.GetSize() > 0)
return true;
else
return false;
while(fUserList.ReadString
{
arUsers.Add(strLine);
}
if(arUsers.GetSize() > 0)
return true;
else
return false;
Please post the full code for function GetListFromFile,
to include function declaration.
Also can you post the code calling GetListFromFile? Starting from the section that declares the CStdioFile object, to the point where you call GetListFromFile.
to include function declaration.
Also can you post the code calling GetListFromFile? Starting from the section that declares the CStdioFile object, to the point where you call GetListFromFile.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BOOL GetListFromFile(CStdioFile &fUserList); // declaration
//definition
GetListFromFile(CStdioFile &fUserList)
{
CString strLine;
while(fUserList.ReadString (strLine))
{
arUsers.Add(strLine);
}
if(arUsers.GetSize() > 0)
return true;
else
return false;
}
CStdioFile fUsers; // declared in .h file
fUsers.Open("C:\\UserID.in f", CFile::modeCreate || CFile::modeNoTruncate || CFile::modeRead, &e);
if(!lstUsers.GetListFromFi le(fUsers) )
MessageBox("No Clients On File.","No Clients",MB_ICONERROR);
//definition
GetListFromFile(CStdioFile
{
CString strLine;
while(fUserList.ReadString
{
arUsers.Add(strLine);
}
if(arUsers.GetSize() > 0)
return true;
else
return false;
}
CStdioFile fUsers; // declared in .h file
fUsers.Open("C:\\UserID.in
if(!lstUsers.GetListFromFi
MessageBox("No Clients On File.","No Clients",MB_ICONERROR);
BTW, to elaborate - by using
fUsers.Open("C:\\UserID.in f", CFile::modeCreate || CFile::modeNoTruncate || CFile::modeRead, &e);
you're effectively setting 'modeWrite', which is certainly not what you want to do.
fUsers.Open("C:\\UserID.in
you're effectively setting 'modeWrite', which is certainly not what you want to do.
>>since you want to use a binary OR, not a boolean.
Good catch!
Good catch!
ptrennum,
I thought you change your code to get rid of modeCreate, as I previously pointed out?
You should just open it with CFile::modeRead
fUsers.Open("C:\\UserID.in f", CFile::modeRead, &e);
I thought you change your code to get rid of modeCreate, as I previously pointed out?
You should just open it with CFile::modeRead
fUsers.Open("C:\\UserID.in
Are you opening the file first?
Please post the code that opens the file.
Does it crash when it hits the start of the loop or within the loop itself?
David Maisonave :-)
Cheers!