学习篇---标准库类型中细节巩固问题

标准库string类型

1.string类型的初始化

2.string类型的输入操作符注意的问题

3.getline 读取整行文本

4.string中的size的返回类型是什么?为什么不能返回int型?

5.string'中和字符串字面值的连接 (+操作符) 加操作符返回的是string对象

6. string 对象s, s[s.size()-1] 表示的是什么

7. 采用C标准库头文件的C++版本


标准库vector类型

1.vector对象的定义和初始化

2.vector对象的操作

3. 求count的值

/**
 * Copyright (C) 2014, CSU
 * All rights reservedl
 * File Name:test.cpp
 * Author: lmm
 * Date of completion: 2014/10/6
 * Version: v1.0
 * 
 * Problem description:read words from the standard input and store them as elements in a vector,count numbers of whitespace-separated string 
 * Input description: input words
 * Program output: an integer
 */

#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
#include <vector>
using namespace std;
#define MAX_PATH 260
int main()
{
    vector<string> text;
    string word;
    vector<string>::size_type cnt = 0;
    while(cin >> word )
    {
        ++cnt;
        text.push_back(word);
    }
    cout << "Count: " << cnt << endl;
    return 0;
}


4.vector的下标操作只能用于获取已存在的元素,必须是已存在的元素才能用下标操作符进行索引。通过下标操作进行赋值时,不会添加任何元素。

5.区分const_iterator 和 const的iterator (3.21)

 

标准库bitset类型

1.初始化bitset对象的方法

2.测试题:考虑这样的序列:1,,2,3,5,8,13,21,给定一个空的bitset对象,编写一小段程序把相应的数位置1

/**
 * Copyright (C) 2014, CSU
 * All rights reservedl
 * File Name:test.cpp
 * Author: lmm
 * Date of completion: 2014/10/6
 * Version: v1.0
 *
 * 问题描述:考虑这样的序列:1,,2,3,5,8,13,21,给定一个空的bitset对象,编写一小段程序把相应的数位置1
 * 输入描述: 空的bitset对象
 * 程序输出: 输出bitset对象的位模式
 */

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
    bitset<32> bv;
    int x = 0, y = 1, z;
    z = x + y;
    while(z <= 21)
    {
        bv.set(z);
        x = y;
        y = z;
        z = x + y;
    }
    cout << "The value of all bits of bv :" << endl << bv << endl;
    return 0;
}


注意:设置为1的数位的位编号符合斐波那契数列的规律

总结:今天主要温习巩固标准库类型中需要注意的小细节问题,问题涉及的不够全面,后续继续添加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值