Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading CFile object contents in a CString obj

Status
Not open for further replies.

rishabhs

Programmer
Nov 25, 2002
5
US
hi techies!

i've just started to work in MFC & VC 6.
i want to read contents of a CFile objects in a CString object.
How do i go 'bout it.
If some1 could help me.
pleeeeeeeeeeeeeeeeeeeeeeeeeeeeseeeeeeeeeeeseeeeeeeeeeeeeeee
 
If you're using a Text file try this:

try
{
CString sFileLine;
CStdioFile fileRead(sFilePathName, CFile::modeRead |
CFile::typeText);

while (fileRead.ReadString(sFileLine))
{
....whatever
}
}
catch (CFileException* e)
{
e->ReportError();
e->Delete();
}

 
If you're not using a text file then you'd be better of declaring an array of 'unsigned char' type to hold the info:

[tt]unsigned char* buffer = new unsigned char[bufferSize];

// read stuff into buffer here

// don't forget to 'delete' the buffer when finished!
delete []buffer;[/tt]

tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Forgot to mention - this is because if you use a CString, it will get chopped off at any zero character!
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top