Agreeing with fabi here. cin.get() is a lot cleaner, more portable, and faster than system("PAUSE"). What I fail to understand is why you would recommend this method and then link to an article explaining why NOT to use it!
In addition, there are two things you could do to make your above code look cleaner. First off, if you plan on using cout a lot you should really declare usage for it. Put "using std::cout" at the top so you can just type "cout" instead of "std::cout" which looks a lot nicer. You could also just include the entire std namespace, but that might be overkill and could cause problems with other custom classes, methods, etc.
Another thing to do is to stop using endl in the context that you did. If you simply want to put two newlines, I'd just use "\n\n" since it is shorter, doesn't require another << stream, and doesn't flush the output buffer (not needed in this case).
I know you probably weren't writing this with the intention of anyone criticizing it, but take this as a lesson. This is how I would have done it (with only the changes mentioned):
- Code: Select all
#include <iostream>
#include <cstdlib>
using std::cout;
int main(int argc, char* argv[])
{
cout << "This is a test...";
cin.get();
cout << "That was the test!\n\n";
return 0;
}
Try compiling it. Not only does it avoid the ugly "PRESS ANY KEY I AM WINDOWS SUCK MY DICK" message, but the code itself is a lot easier to read. Granted, this will only accept the Enter key, but that's a small price to pay, and (in my opinion) more desirable in most cases.
http://www.cplusplus.com/forum/beginner/25538/http://stackoverflow.com/questions/2139 ... dendl-vs-nhttp://cppkid.wordpress.com/2008/08/27/ ... o-stdendl/