65,186
社区成员




pFile = fopen("***.***", "r+t");
nRead = fread(缓存, sizeof(缓存类型), 文件大小, pFile);//把全部文件读到内存
//while(szBuf != '\0')//文件结构有规律可以用循环
{
nFirst = nLast = 0;
//Loop_info
nLast = find(szBuf, ":", nFirst);
szBuf(0, nLast)->szTemp;
szTemp[nLast] = '\0';
nFirst = nLast;
//Radial
nLast = find(szBuf, "\n", nFirst);//\r\n?
szBuf(nFirst, nLast)->szTemp;
szTemp[nIndex] = '\0';
nFirst = nLast;
//Relay_num
nLast = find(szBuf, ":", nFirst);
szBuf(nFirst, nLast)->szTemp;
szTemp[nLast - nFirst] = '\0';
nFirst = nLast;
//9
nLast = find(szBuf, "\n", nFirst);
szBuf(nFirst, nLast)->szTemp;
szTemp[nIndex] = '\0';
nRelayNum = atoi(szTemp);
nFirst = nLast;
//继续解析
}
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile("file.txt");
string strWord;
if (!infile)
{
fprintf(stderr,"cannot open exam.txt !\n");
return 1;
}
while (infile)
{
infile>>strWord;// get a word
// 再处理下
}
return 0;
}