c++ - "else"DevC++ 之前的预期主表达式

标签 c++ compiler-errors

我在这部分代码中收到错误“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/

相关文章:

c++ - 纹理坐标不对应于 cv::Mat 坐标

c++ - 如何反汇编 Pro*C/C++ 程序?

c++ - 初始化多个指针时出现运行时错误

c# - 当缺少System指令时,如何解析类型别名?

c++ - 比较std::ostream to see if it is std::cout (“no match for ' operator= ='” )

c++ - Windows API - 初学者帮助

C++ 没有捕获 lua 异常

java - 编译时"error: cannot find symbol";我尝试使用的类 "cannot be found"

.net - 错误1编译时无法复制文件

java - “找不到符号”或“无法解析符号”错误是什么意思?