【问题解决】C++标准输入输出问题。

本文介绍了C++初学者遇到的'cout'未声明错误,解析了错误原因,指出需要引入iostream头文件并使用命名空间std。通过添加'using namespace std;'或者在cout和endl前指定std来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

头一次接触C++,尝试输出一些东西时报错。代码如下:

#include <iostream>

int main(int argc, char** argv) {
	cout <<3.4 <<endl;
	return 0;
}

报错为:

[Error] ‘cout’ was not declared in this scope

也就是说,输入输出关键字没有被声明。
返回头文件iostream中查看后发现有一个像函数一样的东西,代码如下:

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  extern istream cin;		/// Linked to standard input
  extern ostream cout;		/// Linked to standard output
  extern ostream cerr;		/// Linked to standard error (unbuffered)
  extern ostream clog;		/// Linked to standard error (buffered)

#ifdef _GLIBCXX_USE_WCHAR_T
  extern wistream wcin;		/// Linked to standard input
  extern wostream wcout;	/// Linked to standard output
  extern wostream wcerr;	/// Linked to standard error (unbuffered)
  extern wostream wclog;	/// Linked to standard error (buffered)
#endif
}
  static i
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值