您的位置:首页 > 其它

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

2014-10-06 10:16 204 查看
标准库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的数位的位编号符合斐波那契数列的规律

总结:今天主要温习巩固标准库类型中需要注意的小细节问题,问题涉及的不够全面,后续继续添加
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: