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

巧了我就是萌 提交于 2019-12-13 05:24:53

问题


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

I keep getting error: 'cout' was not declared in this scope. warning: character constant too long for its type (enabled by default)


回答1:


You need

#include <iostream>

That's where std::cout is defined. (And you don't need #include <ostream>.)




回答2:


You have a syntax error, where:

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

you have those single quotes, causing you to pass the << operator twice in a row.

Also, use

#include <iostream> 



回答3:


std::cout is defined in . Try changing your include from to .

Also, your ' << i1 << ' should be in double quotes if you want it to be a string.



来源:https://stackoverflow.com/questions/26199415/error-cout-was-not-declared-and-is-giving-me-compiling-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!