I'm writting a program which will read a text file with an input similar to this
我编写的用于读取输入文件的代码将其存储为字符串数组,每个元素代表输入文件中的一行:
string line;
string InputInstruct[19] = {};
int currentLine = 0;
ifstream myfile("example.txt");
string PreDefinedInstruction[19] = {"ADD","ADDI","SUB","AND","ANDI","OR","ORI","NOR",
"SLL","SRL","SRA","STL","SLTI","LUI","LW","SW","BEQ","BNE","J"};
if (myfile.is_open())
{
while (getline(myfile, line))
{
// cout << line << '\n';
InputInstruct[currentLine] = line;
currentLine++;
}
myfile.close();
}
else cout << "Unable to open file";
我想尝试将InputInstruct数组中每个元素的第一个单词与PreDefinedInstructions的元素进行比较,如果我发现其中的一个,则调用特定函数...不确定如何执行此操作,欢迎提供帮助。
谢谢。
- -编辑 - -
我还想阅读'$'之后的数字,也许还要阅读每个''之后的数字,这就是为什么分词似乎很有意义的原因。