C++PPlus学习【第二章代码】

由于研究阶段主要在SLAM方向,因此我也感觉我(孱弱的C++)基础将对我的研究产生不好的影响,因此打算学习C++P PLUS,以后可能要学习数据结构C++版本的。第二章感觉相比谭浩强教科书版本能给我提供的思考点更多,当然第二章还是十分基础的,都能够看明白。

由于未来基本在linux环境下搭建工程,因此稍微了解了一下cmake。在clion上配置文件,由于工程文件不能够支持使用多个main函数,因此需要以下步骤解决。

解决linux上clion工程下多个main函数的问题】首先新建一个工程文档,把他自带的main删除掉
在这里插入图片描述然后新建一个Cpp文件,这时候直接reload就可以运行。但是有两个cpp文件时,就会存在两个main函数,直接运行是不可以的,需要修改cmakelist
在这里插入图片描述
注意cpp文件前面必须不一样,不然相当于两个是同一个下面的cpp,然后点这里选择
在这里插入图片描述
最后运行就ok

【变量名设置问题】
这个问题在做书上的第二题的时候发现自己设置了一个变量名long,然后运行不过去,以后还是得多注意啊。

下面贴了一下自己完成的课后代码,刚开始还是比较简单的,希望自己坚持下去,加油!

2.1.cpp
#include "iostream"
//using namespace std;
using std::cout;
using std::endl;
int main()
{
    //std::cout<<"QIUF"<<std::endl;
    cout<<"QIUF"<<endl;
}

2.2.cpp
#include "iostream"
using namespace std;

int main()
{
    int distance;
    cin>>distance;
    cout<<"码数为 "<<220*distance<<endl;
    return 0;
}

2.3.cpp
#include "iostream"
using namespace std;

void pout(void);
void pout2(void);

int main()
{
    pout();
    pout();
    pout2();
    return 0;
}

void pout(void)
{
    cout<<"Three blind mice"<<endl;
}

void pout2(void)
{
    cout<<"See how they ran"<<endl<<"See how they ran";
}

2.5.cpp
#include "iostream"
using namespace std;

int zhuanhua(int);

int main()
{
    int she;
    cin>>she;
    cout<<"Please enter: "<<she<<endl;
    int hua;
    hua=zhuanhua(she);
    cout<<she<<" degree celsius is "<<hua<<" degree huashi";
}

int zhuanhua(int a)
{
    int b;
    b=1.8*a+32.0;
    return b;
}

2.7.cpp
#include "iostream"
using namespace std;

void screen(int a,int b);

int main()
{
   int hour;
   int minute;
   cin>>hour;
   cin>>minute;
   screen(hour,minute);

}

void screen(int a,int b)
{
    cout<<"enter the number of hours: "<<a<<endl;
    cout<<"enter the number of hminutes: "<<b;
}

太简单了运行结果就不贴了orz

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值