2
每次運行此方法時,它都會一直返回我輸出的錯誤消息。例如: 用戶輸入:調試我的程序
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();
}
'tokenize()'中存在一個很難從這裏發現的錯誤。不要在'error_return'行上設置斷點? – molbdnilo