c++ hello world

c++的hello world

// 引用c++的头文件
#include "iostream"
// 使用命名空间, std标准的命名空间, 在这个空间里定义了很多标准定义
using namespace std;

// c++新标准main需要返回int值
int main() {
	// cout<<输出后面引号中的字符串,endl是相当于回车换行
	// <<endl 必须写全, 只写<</endl都不行
	cout<< "hello..."<<endl;
	cout<< "world..."<<endl;
	double pi = 3.14;
    // 这种写法可以连续输出需要的信息
	cout<<"pi = "<< pi << " end";
	// endl相当于换行
	cout<<endl;
	cout<<"anthor line"<<endl;
	return 0;
}

输出结果如下:

g++ hello.cpp -o hello, 是将hello.cpp源码编译成可执行的文件, 名字是hello,  ./hello是执行刚刚编译好的可执行文件

猜你喜欢

转载自blog.csdn.net/c1392851600/article/details/83830476