1.利用puts()输出
#include<cstdio> // puts
int main()
{
puts("Hello, world!"); // 输出
}
#include <stdio.h> // puts
int main()
{
puts("Hello, world!"); // 输出
}
2.利用printf输出
#include <stdio.h> // printf
int main()
{
printf("Hello, world!\n"); // 输出
}
3.利用cout输出
#include <iostream> // cout
int main()
{
std::cout << "Hello, world!\n"; // 输出
}
#include <iostream> // cout
using std::cout; // 使用std名字空间的单个名字cout
int main()
{
cout << "Hello, world!\n"; // 输出
}
#include <iostream> // cout, endl
using namespace std; // 使用名字空间std(的任何名字)
int main()
{
cout << "Hello, world!" << endl; // 输出
}
4.总
#include <cstdio> // puts, printf
#include <iostream> // cout, endl
using namespace std; // 使用名字空间std(的任何名字)
int main()
{
puts("1. Hello, world!"); // 输出
printf("2. Hello, world!\n"); // 输出
cout << "3. Hello, world!\n"; // 输出
}
本文介绍了C++中常见的三种输出方式:使用puts()、printf()以及iostream库中的cout,详细讲解了每种方法的用法,适合初学者入门。
1万+

被折叠的 条评论
为什么被折叠?



