Cout不命名类型
cout does not name a type
我是c++的新手,我在"hello world"程序上,我一直得到错误
"cout"没有命名类型,我在Ubuntu上使用的是geany,如果有区别的话,下面是我的代码:
#include <iostream>
int main ()
{
extern cout << "hello world!";
return 0;
}
我不想做一个新的问题,所以我要把它添加到这里
有了提供的修订,它现在可以编译了,但是当我运行程序时,我得到了错误
./geany_run_script.sh: 5: ./geany_run_script.sh: ./hello: not found
对此有什么想法吗?
将extern
改为std::
。第一个问题是extern
仅在类型名称之前有效,所以这就是编译器抱怨的问题。第二个原因是cout
在名称空间std
中定义,因此需要告诉编译器在那里查找。好在代码没有写using namespace std;
。
变化:
extern cout << "hello world!";
也std::cout << "hello world!"; // You probably want n on the end.
这是因为cout
是在命名空间std
中定义的对象。因此,您需要通过给它加上std::
前缀来让编译器知道在哪里可以找到它。有几种可选择的技术,但在我看来这是最好的。
备选方案:使用using directive
using std::cout;
cout << "hello world!";
using std::cout;
告诉编译器std
中有一个叫做cout
的对象,我们想在本地使用它,它被带到当前上下文中,从而允许你直接使用它。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 错误:在尝试检测 std::cout 是否<< t 时,功能强制转换为数组类型;有效
- 使用 CIN 和 COUT 在 C++ 中声明基本数据类型
- 如何根据定义的字符串类型在“std::cout”和“std::wcout”之间进行选择
- cin和cout如何支持不同的数据类型
- 通用 cout,可以是 wcout,具体取决于类型定义
- cout/cin没有命名类型错误
- cout 如何区分基本类型
- cout如何知道如何格式化不同的类型
- c++的cout操作数错误,类型错误
- 如何使用cout正确打印long long int类型
- "cout"未命名类型错误
- Std::cout, ostream和其他类型的获取输出流
- 如何正确地在c++中打印double类型的cout
- Cout不命名类型