Horribly dumb question

Please brace yourself for my ignorance as I am EXTREMELY new to C++ and programming in general.

I have been following a long with a tutorial from my C++ book and a few online information hubs I've run across (including this fantastic forum)

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// my includes and namespace

#include <iostream>
#include <limits>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 90;
  b = 30;
  result = a - b;

  // print out the result:
  cout << result; 
  cout <<"\n";


  // Enter to close
  std::cout << "Press ENTER to close window...";
  std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

  return 0;
 }


If you notice, I have recently discovered a method of creating a new line in my "application" using ccout <<"\n";

My question is.... Is this the best way to generate a new line in my console? is there a more widely accepted method or faster?

For your example personally I would do

cout << result<<endl;


But I'm pretty new too, and both work just as well.
You can use endl to generate a new line. Try the following to generate three new lines:
 
cout << endl << endl << endl;


Also, endl flushes the buffer for buffered streams, "\n" does not. also I find it easier to simply type endl then hitting shift twice to get the double quotations. It's a matter of preference, if you're not heavily using buffered streams.
Last edited on
Thanks guys. I think using "endl" flows better with my typing preference as well.
Topic archived. No new replies allowed.