|
|
发表于 2004-6-17 16:37:31
|
显示全部楼层
我也刚开始用Linux,发现在Linux下写C和Win下一样,C++稍微有点区别。
给个例子你看:
- // hello.cpp
- #include<iostream> //不是<iostream.h>
- using namespace std; //这个在Win下没有
- class A
- {
- public:
- void out(void);
- };
- void A::out(void)
- {
- cout<<"My First Linux Program!"<<endl;
- }
- int main(void) //不能是void main(void) 必须返回整型
- {
- A a;
- a.out();
- return 0;
- }
复制代码
编译:
g++ -o hello hello.cpp
将生成名为hello的可执行文件。
ps:如果是C程序的话用gcc编译:
gcc -o hello hello.c |
|