我正在编写自定义函数来获取 XML 文件中的所有标签。我正在使用这段代码:
wchar_t *GetLine(wchar_t *fileName=L"indexing.xml", wchar_t endSymbol = '\n')
{
SetFilePointer(hReadFile,sizeof(wchar_t) * position, NULL, FILE_BEGIN);
int size;
wchar_t wchr[1];
DWORD dw;
size = 0;
do
{
ReadFile(hReadFile, wchr, sizeof(wchar_t), &dw, NULL);
if(!dw)
{
break;
}
tempGetLine[size] = wchr[0];
size++;
}while(wchr[0] != endSymbol);
tempGetLine[size] = '\0';
position += (size);
return tempGetLine;
}
wchar_t *GetTag(wchar_t *fileName = L"indexing.xml")
{
wchar_t *temp = GetLine(fileName,'>');
int i = 0;
while(*temp != '\0')
{
tempTag[i] = *temp;
i++;
temp++;
}
tempTag[i] = '\0';
return tempTag;
}
它可以工作,但在一个大文件中它需要很多迭代。如何优化我的代码?