-2

I want to print my name ten times in new lines. Here is my code:

#include "stdafx.h"

#include<iostream>


using namespace std;
void main()
{



    int i;

    for (i = 1; i <= 10; ++i)
        cout <<   "krishna "  ;
    getchar();

}

I need a break or "\n" after the first row of printing. How to get that ?

lulyon
  • 6,707
  • 7
  • 32
  • 49
Krishna Mohan
  • 175
  • 1
  • 6
  • 14

2 Answers2

0

You should NOT use std::endl;

for (i = 1; i <= 10; ++i)
    cout <<   "krishna "  << endl;

Its indeed (after getting an comment) better to use '\n' (Windows only)

Look at this FAQ -> https://isocpp.org/wiki/faq/input-output#endl-vs-slash-n

Kevin
  • 506
  • 6
  • 13
  • 4
    Most of the time you actually do not want to use `std::endl`: http://stackoverflow.com/questions/8311058/n-or-n-or-stdendl-to-stdcout – NathanOliver Mar 21 '16 at 13:10
0

You can use Both endl or '\n'.your code will look like this-

for (i=1;i<=10;i++)
cout<<"Krishna\n";
Hamim
  • 1
  • 2