You are here:

C++/Programming difference

Advertisement


Question
Hi, I'm a C++ newbie currently taking the C++ Beginneer's guide. I'm approaching the end of the book and as I search for example programs, I've discovered that I program in a very different way from the usual. For example, I use
cout << "a is 1";  // instead of
cout << "a is 1" << endl;
and many other places, can you explain why, is my method of programming correct? If possible, can you provide a list of differences between these methods of programming?

tahnks

Answer
Hey, Angela.

As I mentioned in the question that you sent me directly a few days ago, coding style is extremely subjective, and just about everybody has a different style in one way or another.  There is no right or wrong when it comes to coding style, as long as you follow the semantics of the language.

This particular example, the only difference between the two lines is that, in your code, you don't terminate the line.  The endl code simply adds a newline character, same as adding a \n to the end of your line.  Neither method is incorrect, it's just that one of them inserts a newline to bring the cursor to the next line.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joseph Moore

Expertise

I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.

Experience

I've been writing C++ code for 12 years, both on my own in my spare time and professionally.

Organizations
IGDA

Education/Credentials
Bachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and Honors
Salutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004

©2016 About.com. All rights reserved.