【问题标题】:error: cout was not declared and is giving me compiling problems错误:未声明 cout 并给我编译问题
【发布时间】:2014-10-05 03:42:00
【问题描述】:
#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”未在此范围内声明。
警告:字符常量对其类型来说太长(默认启用)
【问题讨论】:
标签:
c++
compiler-errors
cout
【解决方案1】:
你需要
#include <iostream>
这就是定义std::cout 的地方。 (而且你不需要#include <ostream>。)
【解决方案2】:
您有语法错误,其中:
cout << c << ' << i1 << ' << c2 << '\n';
你有那些单引号,导致你连续两次传递
另外,使用
#include <iostream>
【解决方案3】:
std::cout 定义在 .尝试将您的包含从更改为 。
另外,如果你希望它是一个字符串,你的 '