cfile question
-
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way? int filelen = 0; CString Cbuf; ...... if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){ filelen = rfile.GetLength(); if(filelen>0){ rfile.Read(Cbuf,filelen); ........ thank you.
-
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way? int filelen = 0; CString Cbuf; ...... if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){ filelen = rfile.GetLength(); if(filelen>0){ rfile.Read(Cbuf,filelen); ........ thank you.
jafrazee wrote: but can i load the entire contents of a file into a CString? or is there a better way? If it's a file of reasonable length, then the answer is you can. But it's not recommended for binary files. But say you have some kinda textual config file which you want to parse. Nothing wrong in reading it into a CString even if it goes to 10-20 KB Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)
-
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way? int filelen = 0; CString Cbuf; ...... if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){ filelen = rfile.GetLength(); if(filelen>0){ rfile.Read(Cbuf,filelen); ........ thank you.
if you use the std library, it's very easy to read the entire contents of a file into a string. I show how in my STL series of articles. If CFile won't do the same then it is more pathetic than I thought. Either way, it's generally better to use the std library. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
-
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way? int filelen = 0; CString Cbuf; ...... if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){ filelen = rfile.GetLength(); if(filelen>0){ rfile.Read(Cbuf,filelen); ........ thank you.
LPTSTR psz = Cbuf .GetBuffer (filelen); rfile .Read (psz, filelen); Cbuf .ReleaseBuffer (); Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
if you use the std library, it's very easy to read the entire contents of a file into a string. I show how in my STL series of articles. If CFile won't do the same then it is more pathetic than I thought. Either way, it's generally better to use the std library. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
Bah, there is nothing (for the most part) wrong with CFile. It is just a wrapper for file IO, nothing more. No point in adding 80k of code to you program just to read a simple file. If that is all he needs to do, then CFile will work just fine. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
LPTSTR psz = Cbuf .GetBuffer (filelen); rfile .Read (psz, filelen); Cbuf .ReleaseBuffer (); Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
Bah, there is nothing (for the most part) wrong with CFile. It is just a wrapper for file IO, nothing more. No point in adding 80k of code to you program just to read a simple file. If that is all he needs to do, then CFile will work just fine. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
I guess it depends on your POV. I use STL and iostreams a lot, and a lot within the one project. I could not live without the facilities it offers me, which CFile/CArray does not. The average programmer seems blissfully unaware that such facilities exist, and so will suffer CFile when on a large scale project, where the 80k or so that gets added would be of real benefit to them. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002