解决问题 “error: `cout' was not declared in this scope”

本文介绍了一个常见的C++编程错误:使用cout和endl时出现的未声明错误,并提供了两种解决方案:一是通过显式地使用std命名空间的成员;二是引入using namespace std;来简化代码。
部署运行你感兴趣的模型镜像

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;
}

您可能感兴趣的与本文相关的镜像

Linly-Talker

Linly-Talker

AI应用

Linly-Talker是一款创新的数字人对话系统,它融合了最新的人工智能技术,包括大型语言模型(LLM)、自动语音识别(ASR)、文本到语音转换(TTS)和语音克隆技术

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值