Hello:
I study use VC++ 6.0 MFC ScrollView Class read a
text file .How to open the text file and read it use
VC++ program.I think it different with C program.
Can VC++ only read binary file?
How to start?
Would you help me ?
Thank you!
To read a text file, construct a CStdioFile object. Call its Open() method with the filename and CFile::modeRead|CFile::typeText as the attributes. Then call its ReadString() method until it returns FALSE (end of file). Then call its Close() method. Like this:
Hello:
Mr. Jason Teagle Thank you very much!
I'm testing your advice.But I first time use the CStdioFile.
It'S need study (Exp:How to control the read one data of
one time,endln...)
If are there examples about use this on internet?
I use VC++ 6.0 MFC ScrollView class.
Thank you again!
I'm not quite sure what you mean, but if it helps, each call to ReadString() reads just one line of the text file at a time - up to the <CR><LF> at the end of the line.
If you want more help with CStdioFile, CString and text files, e-mail me at [email protected] and I'll gladly help you.
I'm using readstring command to read in data from textfile too.But for my case my data are separated by tab . But Readstring only allows me to read in the data before tab and ignore the rest.
Eg.
I'm not sure what has gone wrong for you, but I just ran a quick test to confirm what I believed - ReadString() should and does (for me) read in the whole line, tabs and all - all pieces of data from that one line in the file appear.
I attach a GIF showing my VC environment, proving it should work - notice that the tabs show as little blocks in "strLine" in the variable window.
Can you perhaps create a completely new project and test JUST that part (open a file and read a line), and if it still fails, show us the code to open the file and read it?
Hi, i've got that part working already.. Thanks..
But the tab are represented by a small block. Can i know how to
extract out the data that are separated by the tab.
eg for your case
This|is|a|test // | represent tab
i need the word "this" to go to 1 edit box
"is" to another, etc.
Originally posted by zephyr79
Hi, i've got that part working already.. Thanks..
But the tab are represented by a small block. Can i know how to
extract out the data that are separated by the tab.
eg for your case
This|is|a|test // | represent tab
i need the word "this" to go to 1 edit box
"is" to another, etc.
Thank U for ur precious help
Use AfxExtractSubString as explained over here. I use it to read files with data separated with tabs. If you have any questions, feel free to ask.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.