摘要: #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 阅读(6862) 评论(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 阅读(159) 评论(0) 推荐(0) 编辑
摘要: #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 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 一、向容器添加元素时 ①vector & string if 储存空间重新分配 迭代器、引用&指针都失效 if 没有重新分配 插入位置之前都有效 ②deque 插入到除首尾外都会失效 if 首尾添加,迭代器失效,其他不失效 ③list & forward_list 都有效 二、从容器中删除元素 ①l 阅读全文
posted @ 2016-09-14 09:18 KennyRom 阅读(162) 评论(0) 推荐(0) 编辑