First of all, I would like to just point out that this is my first post in the cplusplus forums and If I may be posting in the wrong place or something like that then please tell me! I am fairly new to programming in c++ although I have experience with other languages such as Java and Visual Basic. I wrote some code while following the examples for learning to program. I am currently learning about constants. As I know from past experience, it is always best to write your own code for each topic that is covered. I wrote some basic code and it is indeed compiling but it doesnt run the way I was expecting it to and I am not sure why. Basically, I would like some help on why this code:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <string> /*I realize that this is not needed in this program
but I was planning on adding on so that is why it is here*/
#define NEW '\n'
int main ()
cout <<("testing constants(define statement)");NEW;cout <<("second");
system ("PAUSE");/*Only using for personal project. I realize the security
issue around this.*/
Is not printing the word second, on the second line. Instead, It all prints on one line only! If someone could please explain this to me and possibly post some revised code that does what I was expecting that would be awesome of you!
First of all, thank you guys or gals for your fast response. As far as what you said Cheraphy, what is your reason for thinking it should not complile? It looks perfectly fine to me and I seperated the statements with ;. You can right multiple statements on one line you know. Maybe I did not see your point though. Then, Angel, yes I do realize it could have been that simple, the only reason I am not using that is...
1. I am trying to learn the define statement better
2. I may be expanding this in the future and I would like to have the \n defined as NEW just for the purpose of being a bit faster. :) Again though, I do realize there were easier ways I could have done this.
I figured out my issue thanks to all of you. Samuel made me realize that I was not using cout to print a newline. I didn't remember that it was not a function. Thanks to all of you I was able to figure out the issue. I will now be marking this topic as solved!