会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
KennyRom
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
14
15
16
17
18
19
下一页
2016年9月16日
C++primer 练习12.6
摘要: 题目:编写函数,返回一个动态分配的int的vector。将此vector传递给另一个函数,这个函数读取标准输入,将读入的值保存在vector元素中。再将vector传递给另外一个函数,打印读入的值。记得在恰当的时刻delete vector。
阅读全文
posted @ 2016-09-16 10:24 KennyRom
阅读(255)
评论(0)
推荐(0)
2016年9月15日
string的数值转换
摘要: to_string(val); //数值val的string表示 stoi (s, p, b); stol (s, p, b); stoul (s, p, b); stoll (s, p, b); stoull (s, p, b); stod (s, p); //b表示转换的基数, p是size_t指针, 用于保存s中第一个非数值符下标,默认为0
阅读全文
posted @ 2016-09-15 09:19 KennyRom
阅读(197)
评论(0)
推荐(0)
C++primer 9.49
摘要: 题目:如果一个字母延伸到中线之上,如d或f,则称其有上出头部分(ascender)。如果一个字母延伸到中线之下,如p或g,则称其有下出头部分(descender)。编写程序,读入一个单词文件,输出最长的既不包含上出头部分,也不包含下出头部分的单词。
阅读全文
posted @ 2016-09-15 09:11 KennyRom
阅读(263)
评论(0)
推荐(0)
C++primer 9.43
摘要: 题目要求:编写一个函数,接受三个string参数s,oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldVal替换为newVal。测试你的程序,用它替换通用的简写形式,如,将"tho"替换为"though",将"thru"替换为"though"。
阅读全文
posted @ 2016-09-15 08:39 KennyRom
阅读(305)
评论(0)
推荐(0)
2016年9月14日
编写程序,从vector<char>初始化string
摘要: #include #include #include using namespace std; int main() { vectorc = { '1', '2', '3' }; string s(c.begin(),c.end()); cout << s << endl; return 0; }
阅读全文
posted @ 2016-09-14 15:34 KennyRom
阅读(6880)
评论(0)
推荐(0)
容器大小管理操作
摘要: shrink_to_fit 只适用于vector, string, deque capacity 只适用于vector, string c.shrink_to_fit(); 将capacity减少为size c.capacity(); 不重新分配,c可以容纳多少元素 c.reserve(n); 分配
阅读全文
posted @ 2016-09-14 13:58 KennyRom
阅读(168)
评论(0)
推荐(0)
一个forward_list C++primer
摘要: #include #include using namespace std; int main() { forward_list vi = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto it1 = vi.before_begin(); auto it2 = vi.begin(); while (it2 != vi.end()) ...
阅读全文
posted @ 2016-09-14 10:07 KennyRom
阅读(160)
评论(0)
推荐(0)
容器操作使迭代器失效
摘要: 一、向容器添加元素时 ①vector & string if 储存空间重新分配 迭代器、引用&指针都失效 if 没有重新分配 插入位置之前都有效 ②deque 插入到除首尾外都会失效 if 首尾添加,迭代器失效,其他不失效 ③list & forward_list 都有效 二、从容器中删除元素 ①l
阅读全文
posted @ 2016-09-14 09:18 KennyRom
阅读(173)
评论(0)
推荐(0)
2016年9月12日
const放在函数前和函数后
摘要: class c { public: returnType functionName (parameter list) const; //这个函数不会修改类成员 const returnType functionName (parameter list); //返回常量 private: ........... }; ...
阅读全文
posted @ 2016-09-12 22:54 KennyRom
阅读(547)
评论(0)
推荐(0)
返回数组指针的函数形式
摘要: Type(*function(parameter_list)) [dimension] or 使用类型别名 typedef int arr[10]; or using arr=int[10]
阅读全文
posted @ 2016-09-12 19:50 KennyRom
阅读(220)
评论(0)
推荐(0)
上一页
1
···
14
15
16
17
18
19
下一页
公告