我确实尝试过但无济于事。我有工作代码可以打开我告诉它的输入文件。它只适用于.txt文件。我需要它才能打开并最终显示.tab文件。我错过了什么?
#include <iostream>
#include <fstream>
#include "Lexer.h"
using namespace std;
int main()
{
string fname, line;
ifstream ifs; // input file stream
int i;
Token tok; Lexer lexer;
cout << "Enter a file to open" << endl;
while (getline(cin, fname)) // Ctrl-Z/D to quit!
{
ifs.open(fname.c_str(), ios::binary);
if (ifs.fail())
{
cerr << "ERROR: Failed to open file " << fname << endl;
ifs.clear();
}
else
{
while (getline(ifs, line))
{
cout << line << endl;
}
ifs.close();
}
}
return 0;
}