错误:cout 未声明,并且给我带来了编译问题

error: cout was not declared and is giving me compiling problems

本文关键字:来了 编译 问题 cout 未声明 错误      更新时间:2023-10-16
#include <ostream>
#include <string>
using namespace std;
int main()
{
char c = 'x';
int i1 = c;
int i2 = 'x';
char c2 = i1;
cout << c << ' << i1 << ' << c2 << 'n';
}

我不断收到错误:"cout"未在此范围内声明。警告:字符常量对于其类型来说太长(默认情况下启用(

你需要

#include <iostream>

这就是定义std::cout的地方。 (而且你不需要#include <ostream>

您有一个语法错误,其中:

cout << c << ' << i1 << ' << c2 << 'n';

有这些单引号,导致您连续两次传递 <<运算符。

另外,使用

#include <iostream> 

std::cout 在 中定义。尝试将包含从 更改为 。

此外,如果您希望<<i1 <<'应该用双引号引起来。