+ 3

Define cout in C++

I was looking for some C++ stuff and I saw this: #define out cout<< out s; Does it work properly? if it does, is there a point of doing it? OBS: I'm begging with C++

5th Sep 2017, 9:15 PM
Ruan Lima
Ruan Lima - avatar
12 Respostas
+ 12
In addition to Jordans answer: The point of doing so is to reduce the amount of editing one may have to perform when wanting to change hard coded values. However overuse of define could make your code hard to read. Here is that code snippet in code playground. https://code.sololearn.com/c9B8E4U8y1R9/?ref=app
6th Sep 2017, 1:16 AM
jay
jay - avatar
+ 9
https://stackoverflow.com/questions/17043090/why-should-i-avoid-macros-in-c
6th Sep 2017, 2:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
@Ruan. not really. see the link Hatsy provided for more information
7th Sep 2017, 9:12 PM
jay
jay - avatar
+ 5
you have to write " #include iostream " and you will not have problems with the "cout" this lesson is at the beginning of the course "C++". you should read it 😊
5th Sep 2017, 9:34 PM
Ana Lima
Ana Lima - avatar
+ 5
haha, no... it was a coincidence😋
6th Sep 2017, 1:17 AM
Ana Lima
Ana Lima - avatar
+ 4
yes, #define simply pastes code there before the processor gets to it. Couldn't find a good video but just know that it pastes anything afterwords into when it's used.
6th Sep 2017, 12:13 AM
Jordan Chapman
Jordan Chapman - avatar
+ 4
it's just for shorthand, so if you didn't want to write something out that you needed alot in your program, you could use a define. There are other reasons but they aren't as common.
7th Sep 2017, 5:58 PM
Jordan Chapman
Jordan Chapman - avatar
+ 2
cout... ..(c+out).... it is used for the output of c data
6th Sep 2017, 3:47 AM
Frost Even
Frost Even - avatar
+ 2
thank you all for the answers. and Jay for the example code. but is there a good point of doing it?
7th Sep 2017, 5:54 PM
Ruan Lima
Ruan Lima - avatar
+ 1
in c we use print f for print the statement,like this cout use for the print output of the programming coad in c++.
7th Sep 2017, 2:47 AM
pooja patil
+ 1
you can do: #define output cout << x << endl and to call this you do: output(5) which will output number 5
7th Sep 2017, 10:20 AM
Liam Ashdown
Liam Ashdown - avatar
+ 1
thanks
8th Sep 2017, 3:18 PM
Md Harunar Rashid
Md Harunar Rashid - avatar