如何在C++的下一行打印我的名字

how to print my name in next line in C++

本文关键字:一行 打印 我的名字 C++      更新时间:2023-10-16

我想在新行中打印我的名字十次。这是我的代码:

#include "stdafx.h"
#include<iostream>

using namespace std;
void main()
{

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

我需要在第一行打印后休息或""。如何获得?

你不应该使用 std::endl;

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

确实(在收到评论后)最好使用""(仅限 Windows)

查看此常见问题解答 -> https://isocpp.org/wiki/faq/input-output#endl-vs-slash-n

您可以使用 endl 或 ''。您的代码将如下所示-

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