c++中hello,world的几种输出方式
·
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"; // 输出
}
更多推荐


所有评论(0)