code is:
#include <iostream>
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
}
when compile the erro info is below:
test@HuiT43 ~/sutdy $ g++ scat.cpp -o scat
scat.cpp: In function `int main(int, char**)':
scat.cpp:12: error: `cout' was not declared in this scope
scat.cpp:12: error: `endl' was not declared in this scope
the reason is :
This is becuase C++ 1998 requires cout and endl be called 'std::cout' and 'std::endl', or that a proper using directives such as 'using namespace std;' be used.
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "hello world" << std::endl;
}
or
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
}
本文介绍了一个常见的C++编程错误:使用cout和endl时出现的未声明错误,并提供了两种解决方案:一是通过显式地使用std命名空间的成员;二是引入using namespace std;来简化代码。

1253

被折叠的 条评论
为什么被折叠?



