随笔分类 -  c++学习基础代码

摘要:s.insert( itr, t ) s.insert(pos, n, c) s.insert( itr, n, t ) s.insert(pos, s2) s.insert( itr, b, e ) s.insert(pos, s2, pos2, len) s.assign(b, e) s.ins 阅读全文
posted @ 2015-03-02 15:25 SandKing 阅读(4) 评论(0) 推荐(0)
摘要:string s string s(s2) string s("value") string s(n, 'c') string s(b, e) string s(cp, n) string(s2, pos2) string(s2, pos2, len2) #include <iostream> #i 阅读全文
posted @ 2015-03-02 14:25 SandKing 阅读(6) 评论(0) 推荐(0)
摘要:1.顺序容器 vector的优点和缺点 缺点: 插入数据时候慢(数组容量不够时,涉及到数组的移动,复制) 删除中间某元素时慢( 涉及元素的移动 ) 优点:排序比较快 sort( vec.begin(), vec.end() ) --快速排序 可以进行快速查找 binary_search( vec.b 阅读全文
posted @ 2015-03-02 12:49 SandKing 阅读(3) 评论(0) 推荐(0)
摘要:1.vector 是用数组做出来的 数组的优点和缺点 优点:有下标,操作速度快 缺点:大小确定后不能改变 2. capacity和reserve成员 vec.reserve(100) 将vec数组增大到100 vec.capacity() 容量 #include <iostream> #includ 阅读全文
posted @ 2015-02-28 18:38 SandKing 阅读(4) 评论(0) 推荐(0)
摘要:1.赋值与交换( swap ) c1 = c2 c1.swap( c2 ) c.assign( b, e ) c.assign( n, t ) 2.使用assign: 类型兼容即可 3.使用swap : 类型必须相同 #include <iostream> #include <vector> #in 阅读全文
posted @ 2015-02-28 18:08 SandKing 阅读(7) 评论(0) 推荐(0)
摘要:删除元素 c.erase(p) c.erase(b,e) //包括前面,不包括后面 c.clear() c.pop_back() c.pop_front() 注意:c.pop_front() 只适用于 list和deque容器 #include <iostream> #include <vector 阅读全文
posted @ 2015-02-28 17:44 SandKing 阅读(7) 评论(0) 推荐(0)
摘要:访问元素 c.back() c.front() c[n] c.at(n) 注意: c[n]和 c.at(n) 只适合vector 和deque容器 #include <iostream> #include <vector> #include <list> #include <deque> #incl 阅读全文
posted @ 2015-02-28 14:57 SandKing 阅读(5) 评论(0) 推荐(0)
摘要:容器大小的操作 c.size() c.max_size() c.empty() c.resize(n) c.resize(n,t) 注意:resize操作可能会是迭代器失效 #include <iostream> #include <vector> #include <list> #include 阅读全文
posted @ 2015-02-28 14:39 SandKing 阅读(2) 评论(0) 推荐(0)
摘要:1.关系运算符 2.所有的容器类型都可以使用 3.比较的容器必须具有相同的容器类型 4.容器的比较是基于容器内元素的比较 5.容器内元素必须有相应的关系运算符 #include <iostream> #include <vector> #include <list> #include <deque> 阅读全文
posted @ 2015-02-28 14:23 SandKing 阅读(4) 评论(0) 推荐(0)
摘要:c++分割字符串 #include <iostream> #include <string> #include <vector> #include <cassert> using namespace std; int ParseString( vector<string>& vecSave, con 阅读全文
posted @ 2015-02-28 14:04 SandKing 阅读(6) 评论(0) 推荐(0)
摘要:1.在顺序容器中添加元素 2.容器元素都是副本 3.添加元素可能会是迭代器失效 4.避免存储end操作返回的迭代器 #include <iostream> #include <vector> #include <list> #include <deque> #include <string> usi 阅读全文
posted @ 2015-02-28 13:56 SandKing 阅读(5) 评论(0) 推荐(0)
摘要:vector<int>为例 #include <iostream> #include <vector> #include <list> #include <deque> using namespace std; int main( int argc, char** argv ) { //char* 阅读全文
posted @ 2015-02-28 12:50 SandKing 阅读(3) 评论(0) 推荐(0)
摘要:#include <iostream> #include <deque> #include <algorithm> using namespace std; int main( int argc, char ** argv ) { deque<int> deq; deq.push_back(4); 阅读全文
posted @ 2015-02-28 12:46 SandKing 阅读(4) 评论(0) 推荐(0)