+ 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++
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
+ 9
https://stackoverflow.com/questions/17043090/why-should-i-avoid-macros-in-c
+ 9
@Ruan. not really. see the link Hatsy provided for more information
+ 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 😊
+ 5
haha, no... it was a coincidence😋
+ 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.
+ 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.
+ 2
cout... ..(c+out).... it is used for the output of c data
+ 2
thank you all for the answers.
and Jay for the example code.
but is there a good point of doing it?
+ 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++.
+ 1
you can do: #define output cout << x << endl
and to call this you do: output(5) which will output number 5
+ 1
thanks