下面是我在redhat下编写的一个小程序hello
在linux下编写的c++程序一般用 .cpp 结尾
编译的时候用g++而不用cc
下面是整个程序
#include<iostream>
using namespace std;
using std::cin;
using std::cout;
int main(void)
{
cout<<"hello"<<endl;
char a[]="hello";
int i;
for(i=0;i<sizeof(a)/sizeof(a[0]);i++)
cout<<a[i];
cout<<endl;
}
以上就是完整的程序,
编译命令
#g++ hello.cpp
编译通过以后运行输出命令
#./a.out
下面为输出结果
hello
hello