为什么std :: cout而不是简单cout? [英] Why std::cout instead of simply cout?

查看:998
本文介绍了为什么std :: cout而不是简单cout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到所有 cout endl 的错误讯息:

I get these error messages for all cout and endl:

main.cc:17:5: error: ‘cout’ was not declared in this scope
main.cc:17:5: note: suggested alternative:
/usr/include/c++/4.6/iostream:62:18: note:   ‘std::cout’

按照建议,一切都很好。现在我很好奇,为什么我不得不这样做。我们之前在类中使用了C ++,但是我从来没有在这些命令之前写任何 std :: 。这个系统可能有什么不同?

After following the suggestion, everything is fine. Now I am curious, why I had to do that. We used C++ in classes before, but I never had to write a std:: before any of those commands. What might be different on this system?

推荐答案

看起来你的类可能使用预标准C ++。一个简单的方法来告诉,是看看你的旧程序和检查,你看到:

It seems possible your class may have been using pre-standard C++. An easy way to tell, is to look at your old programs and check, do you see:

#include <iostream.h>

#include <iostream>

前者是预先标准的,你只能说 cout ,而不是任何额外的 std :: cout 。您可以通过添加

The former is pre-standard, and you'll be able to just say cout as opposed to std::cout without anything additional. You can get the same behavior in standard C++ by adding

using std::cout;

using namespace std;

只是一个想法。

这篇关于为什么std :: cout而不是简单cout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆