在c++中定义宏的麻烦
Troubles with defining a macro n C++
我想测试一下老师给我们的宏,不知道为什么我一直收到错误信息。有人知道为什么吗?我似乎做不到想办法。
#include <iostream>
#include <string>
#define die(errmsg) {cerr << errmsg << endl; exit(1);}
using namespace std;
int main()
{
int x;
for(;;)
{
cout <<"How are you: " <endl;
cout <<"1) goodn";
cout <<"2) badn";
cin >> x;
if(x != 1 || x != 2)
die("Invalid input");
}
return(0);
}
cout <<"How are you: " <endl;
在第二个<<
中漏掉了一个<
检查这个循环:
for(;;)
{
cout << "How are you: " < endl;
}
在std::endl
之前少了一个<
for(;;)
{
cout << "How are you: " << endl;
}
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 部分定义/别名模板模板参数
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- #为""定义宏;静态";针对不同的上下文
- 如何确保C++函数在定义之前声明(如override关键字)
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在命名空间中定义函数还是限定函数
- 此代码是否违反一个定义规则
- 编译C++时未定义的引用
- 不同翻译单元中不可重载的非内联函数定义
- 为什么在定义函数之前先声明它
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 自定义QVariant麻烦
- 使用基本和用户定义类型的名称查找麻烦
- 通过指针填充自定义的类 - 与构造函数的麻烦
- 在定义模板类、操作符和迭代器时遇到麻烦
- 在c++中定义宏的麻烦