why do people use brackets this way when they are more not newbie?
for (m=0 ; m< 1; m++) {
rather then putting the brackets down.
Why is system("pause") bad?
And do classes come first to learn or vectors? And what are vectors because my teacher told me it is just a word they use but it is not a specific topics.
I don't really know, I would probably recommend just trying to do some projects then as you find gaps in your knowledge and your not able to continue, find out what you need to know and then go and find out how to do it. But maybe before you do that have a look at http://www.cplusplus.com/doc/tutorial/
and make sure you at least kind of know how everything works. Like I said before, you will find out how to do things when you need to.
I'm not personally a fan of learning as you go along, because then you're likely to do something the wrong way because you never learned a better way to do it. I would read through a good book and then go to work on your own projects, but that's just me. As for number 2, it's way awesome xD. Also I put spaces after parentheses because I find it easier to read :/
The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-UNIX environments) than the use of 0 and some nonzero value like 1 or -1. In particular, VMS uses a different convention.
biplav17, I do for loops that way because it makes more sense to me, and because it shortens the code considerably. I also bracket one-line loops on the same line as the conditional for the same reason.
Ex:
1 2 3 4 5 6 7 8 9
myIterator = myListObject.begin();
for(int i = 1; myIterator != myListObject.end(); ++i){ //Bracket here saves me one line.
cout << i << ". ";
(*myIterator)->printName();
cin >> mySelection;
myIterator++;
} //Bracket here helps me see the end of a subset, so the use of a line is appropriate.
myIterator = myListObject.begin();
advance(it, sel - 1); //Edited here.
// get assorted input vaues
myIterator = myListObject.begin();
for(int i = 1; myIterator != myListObject.end(); ++i)
{
cout << i << ". ";
(*myIterator)->printName();
cin >> mySelection;
++myIterator;
}
// walk iterator for some reason
myIterator = myListObject.begin();
for(int i = 0; i < mySelection; ++i)
{
++myIterator;
}
And I think it's a good idea to get into the habit of using post pre increment (in some cases it is more efficient), and to avoid un-debug-steppable code like
for(int i = 0; i < mySelection; ++i){myIterator++;}
Note I expressly forbid code like this when I have input to coding standards. Because debug breakpoints (for Visual C++'s debugger and gdb) require code to be on a distinct line.
Note : yes, I meant pre-incr, as used in the code!
@andy: I do compile the code on separate lines first, just to make sure I didn't miss anything, but then once I know it works, I condense it into a single line...only if the loop is, in fact, only one operation, though. I, too, use spacing to distinguish where something begins and ends, but spacing is very significant to me, as it represents the separation between declarations and definitions, or the area between discrete algorithms. In the example above, even though it was two different for loops, the purpose of the algorithm wasn't complete until the end of the second loop.
As far as walking the iterator, I use a function like this as part of a class, it walks the iterator in the class to a point where I want to perform an operation, after going through the whole list and printing to the screen some sort of representation of which item in the list they're using. Then the user can select '1' for the first option, etc, and when the function ends, the iterator (declared in the class scope, not the function scope) remains at the point where the operation is done. I do that because I use the same code, and don't want to repeat it, for locating an entry to delete, edit, print, etc.
I didn't read the other responses but here are my replies to the original questions:
why is this bad?
There is nothing bad about it. If anything, returning EXIT_SUCCESS would be slightly more portable. Not all platforms expect main to return 0 upon success.
why do people use brackets this way when they are more not newbie?
for (m=0 ; m< 1; m++) {
rather then putting the brackets down.
There is no correlation. Newbies and professionals alike all have preferences and they are split. The only thing that could be agreed upon is that you use whatever convention is already used in a existing module. Neither side wants to see them mixed, although the compiler certainly wouldn't mind.
Why is system("pause") bad?
In small private applications, homework assignments, etc., there is little wrong with it. The main concern is security and the concern becomes much more justified in production systems. Consider a user who acquires administrative access to the machine and replaces the "pause" command with his own program that does whatever it pleases.
And do classes come first to learn or vectors? And what are vectors because my teacher told me it is just a word they use but it is not a specific topics.
I would learn classes first but it's not that important.
And I think it's a good idea to get into the habit of using post increment (in some cases it is more efficient), and to avoid un-debug-steppable code like
I have to disagree on adding blank lines to add structure. I'm not much of a white space fan, and I find it harder to read, as well as just looking bad. Anyhow, it's all personal preference.