搞了一下午,還是沒弄出來求大神解答
uj5u.com熱心網友回復:
整個檔案都讀進來,然后找到自己需要的內容即可uj5u.com熱心網友回復:
讀取檔案內容,然后自己決議uj5u.com熱心網友回復:
CFile::Seekvirtual LONG Seek( LONG lOff, UINT nFrom );
throw( CFileException );
Return Value
If the requested position is legal, Seek returns the new byte offset from the beginning of the file. Otherwise, the return value is undefined and a CFileException object is thrown.
Parameters
lOff
Number of bytes to move the pointer.
nFrom
Pointer movement mode. Must be one of the following values:
CFile::begin Move the file pointer lOff bytes forward from the beginning of the file.
CFile::current Move the file pointer lOff bytes from the current position in the file.
CFile::end Move the file pointer lOff bytes from the end of the file. Note that lOff must be negative to seek into the existing file; positive values will seek past the end of the file.
Remarks
Repositions the pointer in a previously opened file. The Seek function permits random access to a file’s contents by moving the pointer a specified amount, absolutely or relatively. No data is actually read during the seek.
When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.
Example
//example for CFile::Seek
extern CFile cfile;
LONG lOffset = 1000, lActual;
lActual = cfile.Seek( lOffset, CFile::begin );
CFile Overview | Class Members | Hierarchy Chart
uj5u.com熱心網友回復:
MFC 怎么讀取啊 我用 Fstream感覺有點沖突
uj5u.com熱心網友回復:
CString buffer;
ifstream in;
in.open("1.txt");
if(in)
{
char ch;
while (!in.eof())
{
in.read(&ch,1);
buffer=buffer+ch;
}
}
size_t stRead;
CString str="";
char szBuffer[1024];
FILE *fp = NULL;
if(0 == fopen_s(&fp,"LS_monitor.lbu","rb") && fp)
{
while(!(feof(fp)))
{
memset(szBuffer, 0, sizeof(szBuffer));
stRead = fread(szBuffer, 1, 1023, fp);
if(stRead <= 0 || stRead > 1023)
{
break;
}
str +=szBuffer;
}
fclose(fp);
}
uj5u.com熱心網友回復:
FILE *fp;轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/115495.html
標籤:基礎類
