我在这部分代码中收到错误“expected primary-expression before “else””。但是我找不到解决方案。任何帮助将不胜感激。
//create class Date object today
Date today (monthT, dayT, yearT);
// check today date that it is correct
if(!(today.checkDate(monthT, dayT, yearT)))
cout << "Today's date is wrong!" << endl;
return 0;
else
//increment date to get tomorrow
cout << "Tomorrow is " << monthT << ", " << dayT+1 << ", " << yearT << "." << endl;
最佳答案
你错过了大括号:
//create class Date object today
Date today (monthT, dayT, yearT);
// check today date that it is correct
if(!(today.checkDate(monthT, dayT, yearT))) { //<---
cout << "Today's date is wrong!" << endl;
return 0;
} else //<---
//increment date to get tomorrow
cout << "Tomorrow is " << monthT << ", " << dayT+1 << ", " << yearT << "." << endl;
关于c++ - "else"DevC++ 之前的预期主表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24226166/