Linux下使用Eclipse开发第一个C++程序

Linux下使用Eclipse开发第一个C++程序

关于安装Eclipse,可以直接选择Applications——Add/Remove Software,弹出对话框:


选中上面的Eclipse,单击“Apply”按钮即可进行Eclipse的下载安装过程。

初次使用Linux下的Eclipse编程,感觉非常别扭,但是有种新奇感。
使用Eclipse开发第一个HelloWorld的C++程序,过程如下所示:

1、新建工程
新建一个Managed Make C++ Project,工程名称为HelloWorld,如图所示:

单击“Next”按钮,如图所示:


单击“”按钮,完成工程的创建。

2、创建源文件

在上面创建的项目中,添加一个source file名称为main.cpp。
添加代码如下所示:

#include <iostream>
#include <string>
using namespace std;

int main(){
    string yourName;
    cout << "Enter your name please:";
    cin >> yourName;
    cout << "Hello,my good friend,"+ yourName +"!";
    return 0;
}

这时,可以看到控制台上有输出内容:

**** Build of configuration Debug for project HelloWorld ****

make -k all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
../main.cpp:11:2: warning: no newline at end of file
Finished building: ../main.cpp

Building target: HelloWorld
Invoking: GCC C++ Linker
g++ -o"HelloWorld" ./main.o   
Finished building target: HelloWorld

Build complete for project HelloWorld

3、创建运行配置

选择“Run“,会弹出对话框,双击C/C++ Local Application创建一个运行配置,如图所示:


点击“Search Project”按钮,如图所示:



双击选择HelloWorld即可,然后点击Apply,再单击“Run”运行。

可以看到控制台上输出:

Enter your name please:

输入你的名字,测试一下:

Shirdrn

回车,即可看到:

Hello,my good friend,Shirdrn!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值