调试我的程序
Debugging my program
每次我运行此方法时,都会返回输出错误消息。例如:用户输入:
display <table.txt> sortedby <ID>
这是我希望用户在调用显示功能时使用的正确语法。但是,当用户类型使用正确的语法显示时,它会输出我指定的错误消息。
Syntax error: display <intable> sortedby <col_name>
总的来说,在这种方法中,我希望该表以漂亮的格式显示。但这不会超越IF语句。我想知道我是否忽略了可能会返回我的error_message的东西。
void display(Lexer lexer) {
Table table; // create a table from the created table class
vector<Token> tokvec = lexer.tokenize();
// expect [IDENT | STRING] sortedby IDENT
if (tokvec.size() != 4 ||
(tokvec[0].type != IDENT && tokvec[1].type != STRING) ||
tokvec[2].value != "sortedby" || tokvec[3].type != IDENT){
error_return("Syntax error: display <intable> sortedby <col_name>");
return;
}
string fn = tokvec[1].value; // name of the file
string col_name = tokvec[3].value;
table.set_input(fn);
table.scan_input();
table.set_index(col_name);
table.sort();
table.display();
}
我建议您在IF语句中打印出要比较的每个值。其中之一是在应该错误的时候真实的,因此您需要找出它是哪一个。完成此操作后,弄清楚哪个值不应该是什么,然后将错误跟踪到其源。
类似的东西:
cout << tokvec.size() << " doesn't equal " << 4 << " - " << tokvec.size() != 4 << endl;
cout << tokvec[0].type << " doesn't equal " << IDENT << " - " << tokvec[0].type != IDENT << endl;
等。
这将打印出所作的每个语句,然后打印出是否为真。它应该清楚问题在哪里。
相关文章:
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 为什么我的 IExtractIcon 处理程序没有被调用?
- 为什么我的程序在for循环中k=0时返回垃圾值
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 我的程序没有从文件中读取并输入数据
- 我的评分程序无法正常工作
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- 反向功能超出了我的 cpp 程序的范围
- 我的二进制搜索程序只是关闭了
- 为什么我的程序不能显示斐波那契级数?
- 为什么我的程序在使用预留后没有加速?
- 为什么如果我添加这一行,我的程序会不断询问值
- 为什么当我输入较大的数字时,我的程序会到达文件末尾?
- 为什么我的两个 cin 语句没有在程序结束时运行?
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 为什么我的程序在 O0 和 O2 的优化级别返回不同的结果
- C++机器人程序(我的私人服务器)出现问题
- 用C++创建一个写作应用程序(我的第一个项目)(学习C++)