如果您在答案中编写代码,请将其写为就像使用namespace std;一样。否则我很难读到:)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int a; // a is amount of lines in file
string word[100];
int main()
{
ifstream fd("file.txt");
fd >> a;
for(int i=0; i<a; i++)
{
//here goes the code which inputs, let's say, 20 first characters of a line into string array - word[i].
}
fd.close();
return 0;
}
答案 0 :(得分:1)
我考虑到该文件可能有超过100行(这将超过您的switch ($number) {
case 0:
echo "a";
break;
case 1:
echo "b";
break;
case 2:
echo "c";
break;
}
- 数组,并且我还考虑到该文件可能不一致关于word
中所述的行数和实际行数。鉴于此,请尝试以下方法:
a