有如下一段代码
{
CStdioFile file;
file.Open("text.txt", CFile::modeRead | CFile::typeText);
CString str;
CString strTemp;
while(file.ReadString(strTemp))
{
str += strTemp + "r";
}
file.Close();
}
这是从第一行开始,每行读取吧~~~
但如果我想从第6行开始读取,连续读取20行,将每行的内容分别保存到数组变量a[20]中,该怎么办呢?
谢谢解答'
--------------------------------------------------------------------------------
{
CStdioFile file;
file.Open("text.txt", CFile::modeRead | CFile::typeText);
CString str;
CString strTemp;
int i;
i = 0;
while(file.ReadString(strTemp))
{
if (i > 26) break;
str += strTemp + "r";
if (i >= 6)
a[i-6] = str;
i++;
}
file.Close();
}
--------------------------------------------------------------------------------
楼上正解
--------------------------------------------------------------------------------
CStdioFile file;
file.Open("text.txt", CFile::modeRead | CFile::typeText);
CString str;
CString strTemp;
int i;
i = 0;
for (i=0;i<26;i++)
{
file.ReadString(strTemp);
if (i<6)
continue;
else
{
str += strTemp + "r";
a[i-6] = str;
}
}
file.Close();
}