为什么不使用命名空间STD和使用命名空间STD时宏的行为不同?
why is macro acting different while not using namespace std and while using namespace std?
在下面的代码中宏1总是好的
but, 宏2 不工作,如果语句1没有写,为什么会发生这种情况?
#include<iostream>
#include<conio.h>
//using namespace std; //--statement 1
#define l std::cout<< //--macro 1
#define nl std::cout<<endl; //--macro 2
int main(){
l "testing";
nl // this is not working if i dont use statement 1
l "a new line";
getch();
return 0;
}
当语句1未写入宏2产生错误,指出'[error]endl未在此范围内声明'
如果cout<<
是std::cout<<
的短版本,这个错误应该不会发生…
这不是你的MACRO的问题。
endl对象也属于std名称空间,因此您应该使用
std::cout << std::endl;
或
using namespace std;
cout << endl;
相关文章:
- C++ — "算法"库和命名空间"std"
- C++ |匿名命名空间与命名空间 std 冲突
- 命名空间 std:: 不包含可选
- 不使用与左右停止工作命名空间 std 的简单比较
- 命名空间 std 没有成员any_of
- 为什么 Clang 在命名空间'std'中没有名为 'copy' 的成员给出错误
- 有没有办法在不使用命名空间 std 或前缀 std:: 的情况下引用 cout?
- 如何为缺少预定义运算符而不扩展命名空间"std"的标准类型定义运算符>> (istream &, ...)?
- 是否有 GCC 警告,用于使用 C 库中的符号而不是通过命名空间 std?
- C++ ,错误:命名空间'std'中的'shared_ptr'未命名模板类型
- 错误:命名空间"std"中没有名为"invoke_result_t"的类型 GCC-7
- 扩展命名空间 std 以在使用 C++11 时实现make_unique
- 是`使用命名空间std :: literals的安全
- 为什么在全局范围以及命名空间std中定义了size_t
- 什么是"使用命名空间 std;"的好替代方案?
- 使用命名空间 std 时C++ "Reference to overloaded function"错误
- 关于在C++中使用命名空间 std
- 命名空间'std'中的'vector'没有模板类型
- 包含所有命名空间 std 的文件
- 删除命名空间STD,专门针对Hex C 程序的剥夺