C++Primer Plus(第六版)第八章编程练习

本文介绍了C++ Primer Plus第六版第八章的编程练习,涉及知识点包括默认参数、引用作为函数形参、getline的使用、模板的定义与声明、具体化模板以及模板函数的运用。在实践中,作者遇到并讨论了使用codeblocks时的一些注意事项。
摘要由CSDN通过智能技术生成

第一题:
知识点:

  • 使用默认参数时要通过函数原型,因为编译器通过查看原型来获取函数信息;
  • 使用引用作为函数形参,使用时直接将常规变量实参传入,函数会为该变量创建一个引用而非副本,所以准确的说算是一个伪指针,使用该伪指针直接对原始数据进行使用
#include <iostream>
#include <string>

using namespace std;
void show(const string &str,int i = 0);
static int counting = 0;

int main()
{
    string str = "I'm in chaos";
    show(str);
    cout << endl;
    show(str, 50);
    cout << endl;
    show(str, 15);
    cout << endl;
    show(str);
    return 0;
}

void show(const string &str,int i)
{
    counting++;
    if(i != 0)
    {
        for(int j = 0; j < counting; j++)
            cout << str << endl;
    }
    else
        cout << str << endl;
}

第二题
知识点:

  • 没有需要太注意的,主要就是告诉你大的变量用引用
#include <iostream>

using namespace std
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值