提问人:Tim Read 提问时间:12/8/2022 更新时间:12/8/2022 访问量:42
如果要检查这 2 个文件是否存在语法错误,VS c++ 代码的输入文件需要在哪里?
Where do input files for a VS c++ code need to be if these 2 files are to be checked for syntax errors?
问:
#include <iostream>
#include <fstream>
#include<stack>
#include<string>
using namespace std;
int main()
{
stack<char> s;/*created a stack object with char data type*/
string file_name;
cout << "Enter the file name: ";
cin >> file_name;
ifstream testFile;
testFile.open(file_name, ios::in);
char ch;
while (testFile.peek()!=EOF)
{
testFile >> ch;
if (ch == '[' || ch == '(')
{
s.push(ch);
}
if (ch == ']')
{
if (s.empty())
{
s.push(ch);
}
if (s.top() == '[')
{
s.pop();
}
}
if (ch == ')')
{
if (s.empty())
{
s.push(ch);
}
if (s.top() == '(')
{
s.pop();
}
}
}
if (s.empty())
{
cout << "No Syntax Error Occured.";
}
else
{
cout << "Syntax Error Occured.";
}
return 0;
}
大家好。这是我在这里的第一篇文章,我需要调试语法检查程序的帮助。我确定堆栈部分是正确的。我认为错误是由于输出没有显示“发生语法错误”或“未发生语法错误”字样,我仍在学习如何调试和欣赏任何建议。当 covid 刚出现时,我就开始了 IT,由于远程学习,我无法掌握基础知识。就像调试一样。
我期望“发生语法错误”或“未发生语法错误”的输出,但它只是以代码 0 退出。
答: 暂无答案
上一个:错误:输入末尾的预期非限定 ID
评论