温馨提示×

c++ cout如何实现换行输出

c++
小樊
121
2024-08-13 00:34:42
栏目: 编程语言

在C++中,使用cout对象输出内容时,可以使用endl来实现换行输出,例如:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    std::cout << "This is a new line." << std::endl;
    
    return 0;
}

上述代码会输出以下内容:

Hello, World!
This is a new line.

另外,也可以使用\n来实现换行输出,例如:

#include <iostream>

int main() {
    std::cout << "Hello, World!\n";
    std::cout << "This is a new line.\n";
    
    return 0;
}

这段代码也会输出和前面相同的结果。

0