EnlightEND
EnlightEND

Reputation: 3

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

#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)

Upvotes: 0

Views: 5253

Answers (3)

user2879331
user2879331

Reputation:

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> 

Upvotes: 2

d3coy
d3coy

Reputation: 395

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.

Upvotes: 1

j_random_hacker
j_random_hacker

Reputation: 51226

You need

#include <iostream>

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

Upvotes: 3

Related Questions