Problem with reading a file
-
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
-
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
Does
CStdioFile
haveopen
andread
methods? The length parameter to any read function is the amount of data to be read from the file. I believe there is some mistake here. The first parameter to the read function must be a buffer containing some memory and not just a pointer. Look at the example in the documentation of CFile::Read[^].«_Superman_» I love work. It gives me something to do between weekends.
-
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
You never allocate preadbuf, so I'm really amazed that your code doesn't crash here...
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
-
shuzh wrote:
这个东西 貌似很好弄袄
Exactly.
-
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
First you should make up your mind if you want to read the file line by line or read the entire file into a buffer. In case of the former option use
CStdioFile::ReadString()
method, for the latter useCFile::Read()
. -
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
Rakesh5 wrote:
if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength());
This will not even compile. If you want to know why a particular piece of code does not work, at least show the actual code.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hi all, I want to read the content of the file.(say .txt) I am using Read method...But Its not reading the entire contents present in the file rather it reads around 50% of the file. ------------------------- Code Snippet: CStdioFile docfile; WCHAR* preadbuf; if(docfile.open(....)) docfile.read(preadbuf,docfile.getlength()); ------------ Please tell me how to solve this problem. please let me know if you have any queries.. Thanks, Rakesh.
Just a thought. But here goes: You seems to read the file as Unicode, that way every character consists of two bytes in the file. If docfile.getlength() reports the file size in bytes, then you get your 50%. An example, suppose the file is 50 bytes. docfile.getlength() returns 50. But you can read 25 Unicode characters from it. Makes sense?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson