Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to Xcode, can't use cout, only std::cout works

I'm not new to programming but I am new to C++ using Xcode as the IDE. I am not allowed to use cout << "hello"; to print, the compiler complains and only works when I use std:cout <<. What setting in Xcode should be fixed in order to get this working the way I'm supposed to write it for class? Thanks!

like image 955
FoxMcWeezer Avatar asked Oct 05 '13 20:10

FoxMcWeezer


People also ask

What is Cout in C++ with example?

cout in C++. The cout object in C++ is an object of class ostream. It is defined in iostream header file. It is used to display the output to the standard output device i.e. monitor. It is associated with the standard C output stream stdout.

What is the use of stdout in C programming?

It is used to display the output to the standard output device i.e. monitor. It is associated with the standard C output stream stdout. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator (<<).

How to write something to the console using Cout in Python?

Let us start with your function. Since you just want to write something to the console, using cout, you do not need the return value ( see the comments in the code, char is changed in void ). Also, I have changed cout statement to output the ocean string, that you have passed to the function, see the code.

Do you need the return value of Cout in a function?

Please Sign up or sign in to vote. I have rewritten your code, so you can see your mistakes. Let us start with your function. Since you just want to write something to the console, using cout, you do not need the return value ( see the comments in the code, char is changed in void ).


1 Answers

Add using std::cout; somewhere close to the start of your program, after the includes.

Please avoid the temptation to use using namespace std;. It's really a bad habit. Just because you see other people doing it, doesn't make it right. See the FAQ: Why is "using namespace std" considered bad practice?

(Or, of course, you could just get use to typing std::cout.)

like image 149
rici Avatar answered Sep 22 '22 15:09

rici