用下面的格式写数据
file.Open("save.txt",CFile::modeCreate|CFile::modeWrite);
file.Write(&data,sizeof(float));//flaot型
file.Write(&data1,sizeof(float));//float型
file.Write(&strdata,strdata.GetLength());//CString型
file.Write(&strdata1,strdata1.GetLength());//CString型
请问怎样把数据读出来?我只会读float型的,CString型不知怎样读。
if(file1.Open("save.txt",CFile::modeRead))
{
file1.Read(&buf,sizeof(float));//读float型
file1.Read(&buf1,sizeof(float));//读float型
file1.Read(bstr.LockBuffer(), file1.GetLength());//不行
file1.Read(bstr1.LockBuffer(), file1.GetLength());//读不出
}
file.Open("save.txt",CFile::modeCreate|CFile::modeWrite);
file.Write(&data,sizeof(float));//flaot型
file.Write(&data1,sizeof(float));//float型
file.Write(&strdata,strdata.GetLength());//CString型
file.Write(&strdata1,strdata1.GetLength());//CString型
请问怎样把数据读出来?我只会读float型的,CString型不知怎样读。
if(file1.Open("save.txt",CFile::modeRead))
{
file1.Read(&buf,sizeof(float));//读float型
file1.Read(&buf1,sizeof(float));//读float型
file1.Read(bstr.LockBuffer(), file1.GetLength());//不行
file1.Read(bstr1.LockBuffer(), file1.GetLength());//读不出
}
下面我会和你说如何用它
记得接着要:
bstr.GetBufferSetLength(file1.GetLength());http://expert.csdn.net/Expert/topic/1603/1603220.xml?temp=.237179
throw( CMemoryException );Return ValueAn LPTSTR pointer to the object’s (null-terminated) character buffer.ParametersnMinBufLengthThe minimum size of the character buffer in characters. This value does not include space for a null terminator.ResReturns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CString operations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.The buffer memory will be freed automatically when the CString object is destroyed. int nstrlength = strData.GetLength()LPCTSTR szData;
szData = strData.GetBuffer( nstrlength );取出存放的字符数据的指针
filw.write( szData,nstrlength );
strData.ReleaseBuffer();
OK! 这次你的 CString 中的字符数据就存进文件中去了
char* ch=new char[dFileLength+1];
file.ReadHuge(ch,dFileLength);
{
DWORD dFileLength=file.GetLength();
char* ch=new char[dFileLength+1];
file.ReadHuge(ch,dFileLength);
MessageBox(ch);
}