vc按行读文件,如何读取每行的从指定位置开始到指定位置结束的字符啊,比如我的文件内容如下0000 00 e0 fc 65 72 4e 00 14 22 60 c9 69 08 00 45 00 ...erN.."`.i..E.
0010 01 48 11 d6 00 00 80 11 e2 32 0a a4 18 54 0a a4 .H.......2...T..
0020 18 01 00 44 00 43 01 34 e8 75 01 01 06 00 c5 45 ...D.C.4.u.....E
0030 da 72 0b 00 80 00 0a a4 18 54 00 00 00 00 00 00 .r.......T......
0040 00 00 00 00 00 00 00 14 22 60 c9 69 00 00 00 00 ........"`.i....我想读从第7个字节开始到48字节位置,最后得到00 e0 fc 65 72 4e 00 14 22 60 c9 69 08 00 45 00
01 48 11 d6 00 00 80 11 e2 32 0a a4 18 54 0a a4
18 01 00 44 00 43 01 34 e8 75 01 01 06 00 c5 45
00 00 00 00 00 00 00 14 22 60 c9 69 00 00 00 00 我的代码如下 CStringArray strarray;
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
CString strLine;
while(file.ReadString(strLine)) //这里面如何取第7个字节开始到48字节的内容,赋值给下面的字符串数组啊
{
strarray.Add(strLine);
} file.Close(); 请高手指教啊
0010 01 48 11 d6 00 00 80 11 e2 32 0a a4 18 54 0a a4 .H.......2...T..
0020 18 01 00 44 00 43 01 34 e8 75 01 01 06 00 c5 45 ...D.C.4.u.....E
0030 da 72 0b 00 80 00 0a a4 18 54 00 00 00 00 00 00 .r.......T......
0040 00 00 00 00 00 00 00 14 22 60 c9 69 00 00 00 00 ........"`.i....我想读从第7个字节开始到48字节位置,最后得到00 e0 fc 65 72 4e 00 14 22 60 c9 69 08 00 45 00
01 48 11 d6 00 00 80 11 e2 32 0a a4 18 54 0a a4
18 01 00 44 00 43 01 34 e8 75 01 01 06 00 c5 45
00 00 00 00 00 00 00 14 22 60 c9 69 00 00 00 00 我的代码如下 CStringArray strarray;
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
CString strLine;
while(file.ReadString(strLine)) //这里面如何取第7个字节开始到48字节的内容,赋值给下面的字符串数组啊
{
strarray.Add(strLine);
} file.Close(); 请高手指教啊
解决方案 »
- 请教下,VC编译后,怎么没有EXE文件出来,简单而重要的问题
- tinyxml 和msxml 哪个好?我在csdn 上down了个msxml的例子,VS打开后在附加包含库里怎么没看到msxml.lib
- 50分求dll中读取内存数据乱码
- 请大侠帮忙用CSocket实现一个连接服务端并向服务端发送数据/接收数据,关键是在调用Receive时,如果3秒内没有数据到达,就进行下面的操作。
- 关于建立OpenGL窗口问题
- 新手请教:如何做个抽奖程序的界面
- 获得记录集的问题?
- 控制型变量和对象具体上有哪些区别啊??谢谢!!
- 各位大虾能提供些 UDP编程的资料和源码吗?万分感谢..
- ShellExecute问题
- “显示设备组件”与“弹出usb时出问题”俩个问题
- OLE数据库错误,各位请急救!!
只能读取一行后你自己再从strLine里截取
unsigned char temp[100];
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
else
{
file.Seek(7, CFile::begin);
file.Read(temp, 42);
file.Close();
}
DWORD WINAPI SetFilePointer(
__in HANDLE hFile,
__in LONG lDistanceToMove,
__inout_opt PLONG lpDistanceToMoveHigh,
__in DWORD dwMoveMethod
);
// Case One: calling the function with lpDistanceToMoveHigh == NULL
// Try to move hFile file pointer some distance
dwPtr = SetFilePointer (hFile, lDistance, NULL, FILE_BEGIN) ;
if (dwPtr == INVALID_SET_FILE_POINTER) // Test for failure
{
// Obtain the error code.
dwError = GetLastError() ;
// Deal with failure
// . . .
} // End of error handler
//
// Case Two: calling the function with lpDistanceToMoveHigh != NULL
// Try to move hFile file pointer a huge distance
dwPtrLow = SetFilePointer (hFile, lDistLow, & lDistHigh, FILE_BEGIN);
// Test for failure
if (dwPtrLow == INVALID_SET_FILE_POINTER &&
(dwError = GetLastError()) != NO_ERROR )
{
// Deal with failure
// . . . } // End of error handler
我象下面这样调用出错啊
CStringArray strarray;
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
CString strLine;
while(file.ReadString(strLine))
{ strarray.Add(strLine.Mid(7,48-7); //这样调用为何不行啊
}
file.Close();
请wwwllg,mengxianbo921帮忙看看啊
CStringArray strarray;
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
CString strLine;
while(file.ReadString(strLine))
{ strarray.Add(strLine.Mid(0,48-7)); //从0个开始读
}
file.Close();
而从第7个开始读为什么就报错呢
CStringArray strarray;
CStdioFile file;
if( !file.Open("3.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return;
}
CString strLine;
while(file.ReadString(strLine))
{ strarray.Add(strLine.Mid(7,48-7)); //从第7个开始读
}
file.Close();
这样不行么?
感谢wwwllg,mengxianbo921,jourbin