CFile and CString buffer problems

Hi there,
I've been trying to extract file contents using CFile, with a CSting buffer to store it. Then outputting it with no luck could someone take a look at this snipit of my code, and enlighten me of what my problem is.

CFile m_ffile;
CString filename("File.txt");
CString m_strBuffer;
int m_nBufferSize = 100;
char* pbuffer;
pbuffer = new char[m_nBufferSize];

m_ffile.Open( filename, CFile::modeRead| CFile::shareDenyWrite);
while( m_ffile.Read(pbuffer, m_nBufferSize) ){

m_strBuffer += *pbuffer ;
}
cout << (LPCTSTR)m_strBuffer;

Thanks,
s;)

"Do it Kakarotto! your No. 1" - Vegita
[704 byte] By [majin buu] at [2007-11-17 2:25:45]
# 1 Re: CFile and CString buffer problems
Change m_strBuffer += *pbuffer; to
m_strBuffer += pbuffer ;

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 6:58:27 >
# 2 Re: CFile and CString buffer problems
Change this line

m_strBuffer += *pbuffer ;

to

m_strBuffer += pbuffer ;

Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)

Best regards,

----
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor@soukhov.com | ICQ:57404554 | http://soukhov.com
Igor Soukhov at 2007-11-10 6:59:27 >
# 3 Re: CFile and CString buffer problems
You should actualy change your code to this:

CFile m_ffile;
CString filename("File.txt");
CString m_strBuffer;
int m_nBufferSize = 100;
char* pbuffer;
pbuffer = new char[m_nBufferSize + 1]; //One space for terminating NULL
pbuffer[m_nBufferSize] = '\0';
m_ffile.Open( filename, CFile::modeRead| CFile::shareDenyWrite);
while( m_ffile.Read(pbuffer, m_nBufferSize) ){

m_strBuffer += pbuffer ;
}
cout << (LPCTSTR)m_strBuffer;

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 7:00:27 >
# 4 Re: CFile and CString buffer problems
I'm actually trying to read binary files into a buffer then output them, like copy them, keeping the data unchanged. But when I output it or read the buffer it doesn't resemble the original file. I want to put it into memory for efficiency, to manipulate it first. What is my problem.
Thanks for your help.
s;)

"Do it Kakarotto! your No. 1" - Vegita
majin buu at 2007-11-10 7:01:34 >
# 5 Re: CFile and CString buffer problems
Is this binary data? If so, each time the buffer contains a byte with the value of 0, the string will be truncated. How do you want to output the file? Like you see in a hex editor or like you see when you open it in notepad?

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 7:02:33 >
# 6 Re: CFile and CString buffer problems
Umm, well I look at the binary data in notepad, but I want it to be able to run like the original file.

"Do it Kakarotto! your No. 1" - Vegita
majin buu at 2007-11-10 7:03:33 >
# 7 Re: CFile and CString buffer problems
"buffer then output them, like copy them", what exactly are you trying to do? Modify the file and save it? How do you want to output the data? please be more clear on the subject.

Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
--===--
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
--===--
Daniel
DanielK at 2007-11-10 7:04:39 >
# 8 Re: CFile and CString buffer problems
Sorry, well I first am trying to get the data from a binary file into a buffer and out so I know that the data is in it's original form. then after that, try cutting the size down, save it open it up again then convert it back. but just the first step making sure that the data is identical to the file without changing it, isn't working. I want to be able to manipulate the original bytes knowing that they are exactly the same in the file. if that makes sense.
s;)

"Do it Kakarotto! your No. 1" - Vegita
majin buu at 2007-11-10 7:05:31 >