关于安装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!
Linux下使用Eclipse开发第一个C++程序
最新推荐文章于 2021-12-24 14:15:25 发布