6.2.3

6.16

bool is_empty(string& s) { return s.empty(); }

对于const的string 不适应,并且在不改变本体是时候,最后使用const来限制

6.17

#include <iostream>
#include <string>
using std::cout; using std::endl; using std::string;

bool any_capital(string const& str)
{
    for (auto ch : str)
        if (isupper(ch)) return true;
    return false;
}

void to_lowercase(string& str)
{
    for (auto& ch : str) ch = tolower(ch);
}

int main()
{
    string hello("Hello World!");
    cout << any_capital(hello) << endl;

    to_lowercase(hello);
    cout << hello << endl;

    return 0;
}

6.18

bool compare(matrix &m1, matrix &m2){ /.../ }
//比较大小
vector<int>::iterator change_val(int,vector<int>::iterator) { /.../ }
//改变迭代器的位置,或者查找一个数什么的

6.19

double calc(double);
int count (const string &,char);
int sum (vector<int>::iterator,vector<int>::iterator,int);
vector<int> vec(10);
(a)calc(23.4,55.1);     //不合法,只需要一个参数
(b)count("abcda",'a');  //合法
(c)calc(66);            //合法
(d)sum(vector.begin(),vec.end(),3.8);//合法

6.20
值可能会被改变,而这不是你想要的
对于const的数据,这个函数可能不能用了
能用const的时候,一定要用const

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值