1、max_size——容器能申请到的最大容量
#include <iostream> #include <list> int main () { list li(10); cout << "size() of li = " << li.size() << endl; cout << "max_size = " << li.max_size() << endl; return 0; } 运行结果: // size() of li = 10 // max_size = 4294967295
专注Linux下应用与编程
推荐一款Chrome插件Infinity让新标签页焕然一新 Infinity new tab 是一款实用又简洁的chrome新标签页,可以完美替代默认的新标签页。从使用用chrome浏览器开始,就喜欢使用各种插件,屏蔽广告的,印象笔记,当然还有新标签页。由于大学专业的关系,和对于前端的热爱,决定开始自己写一个chrome扩展的新标签页,前期写了米鱼新标签页,v+新标签页。得到很多热心用户的反馈建议,慢慢的发现,这2个产品不能满足用户的一些需求,也没有达到用户心中所期待的一个完美产品。于是决定从新再做一个全新的,能够给人眼前一亮的感觉,也就是...
Android下使用TCPDUMP抓包Wireshark分析数据 如果想分析Android下某个APP的网络数据交互,需要在Android手机上抓包,最常用的抓包工具非tcpdump莫属,用tcpdump生成Wireshark识别的pcap文件,然后将pcap文件下载到电脑上,用电脑上的Wireshark加载pcap文件,通过Wireshark分析tcpdump抓取的数据。...
Mac下部署Android开发环境附加NDK 作为开发者,我们深有体会,不管是进行什么开发,为了部署开发环境,我们往往需要折腾很长时间、查阅很多资料才能完成,而且这次折腾完了,下次到了另一台新电脑上又得重新来过,整个部署过程记得还好,要是不记得又得重新开始,而且遇到Android这种GFW阻隔了开发资源下载链接的环境部署,又尤其浪费时间。所以这也是我写下这篇教程的初衷跟动力源泉,希望大家参考了这篇教程以后可以轻轻松松在Mac系统下将Android环境部署好。...
稍顯嚴肅的台中 坦白說,留在腦海中的台中影像並不多,來台灣之前在Booking上只訂到了台中的一家青旅,第一次住青旅有些不習慣,幹什麼都放不開。 同屋的一個男生是台灣人,不過一年中四分之三的時間在上海跟北京,這麼說來跟我還是比較有共同話題的。得之我準備花15天的時間環島,覺得太倉促了,他們大學時期花一個半月的時間也不見得能將台灣島給逛完。我只能無奈地表示,兩岸允許的簽證時間有限,自己的空閒時間更有限,只能用打卡式的旅行了,我深知正真地旅行應該慢下來,融入當地的環境,感受他們的風土人情,但第一次只能這樣作罷,以後換成民進黨上台,形勢會變成怎樣還不得而知,能否再過來還是個未知數。而我一向信奉的人生格言是秉燭夜遊,活在當下,所以,理解自己吧。...
#include <iostream> #include <list> #include <algorithm> #include <iterator> using namespace std; int main () { int ary[]={1,2,3,4,5}; list<int> l; // 将数组ary分配给l容器 l.assign(ary,ary+5); copy(l.begin(),l.end(), ostream_iterator<int>(cout," ")); cout << endl; // 用3个100替换l容器内容 l.assign(3,100); copy(l.begin(),l.end(), ostream_iterator<int>(cout," ")); cout << endl; return 0; } 运行结果: // 1 2 3 4 5 // 100 100 100
#include <iostream> #include <deque> #include <string> #include <iterator> using namespace std; template <class T> class Name { public: Name(T t) : name(t) {} void print() { cout << name << " "; } private: T name; }; //============================= int main () { typedef Name<string> N; typedef deque<N> D; D d; N n1("Robert"); N n2("Alex"); d.push_back(n1); d.push_back(n2); // unnamed object of the type Name d.push_back(N("Linda")); D::iterator It = d.begin(); while ( It != d.end() ) (It++)->print(); cout << endl; return 0; } 运行结果: // Robert Alex Linda
#include <iostream> #include <deque> #include <iterator> #include <numeric> using namespace std; int main () { deque<int> d(5); iota(d.begin(),d.end(),1); deque<int>::iterator It = d.begin(); while ( It != d.end() ) cout << *It++ << " "; cout << endl; // deque容器的最后一个元素 It = d.end()-1; cout << *It << endl; return 0; } 运行结果: // 1 2 3 4 5 // 5
#include <iostream> #include <deque> #include <string> #include <algorithm> using namespace std; int main () { string str[]={"Alex","John","Robert"}; // 新建一个空的deque对象 deque<int> d1; // 新建一个包含10个元素的deque对象 deque<int> d2(10); // 新建一个包含10个元素的deque对象,并给每个元素赋初始值0 deque<int> d3(10,0); // 新建一个deque对象并用指定区间给元素赋值 deque<string> d4(str+0,str+3); deque<string>::iterator sIt = d4.begin(); while ( sIt != d4.end() ) cout << *sIt++ << " "; cout << endl; // 拷贝构造 deque<string> d5(d4); for ( int i=0; i<3; i++ ) cout << d5[i] << " "; cout << endl; return 0; } 运行结果: // Alex John Robert // Alex John Robert
#include <iostream> #include <vector> #include <string> #include <iterator> using namespace std; template <class T> class Name { public: Name(T t) : name(t) {} void print() { cout << name << " "; } private: T name; }; //============================= int main () { typedef Name<string> N; typedef vector<N> V; V v; N n1("Robert"); N n2("Alex"); v.push_back(n1); v.push_back(n2); v.push_back(N("Linda")); V::iterator It = v.begin(); while ( It != v.end() ) (It++)->print(); cout << endl; return 0; } 运行结果: // Robert Alex Linda
#include <iostream> #include <vector> using namespace std; int main () { vector<int> v; cout << "Vector is "; v.empty() ? cout << "" : cout << "not "; cout << "empty" << endl; v.push_back(100); cout << "Vector is "; v.empty() ? cout << "" : cout << "not "; cout << "empty" << endl; return 0; } 运行结果: // Vector is empty // Vector is not empty
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main ()
{
string str[]={"Alex","John","Robert"};
// 空的 vector 对象
vector<int> v1;
// 新建一个包含10个空元素的 vector 对象
vector<int> v2(10);
// 新建一个包含10个值为0的 vector 对象
vector<int> v3(10,0);
// 新建一个 vector 容器并用string数组初始化
vector<string> v4(str+0,str+3);
vector<string>::iterator sIt = v4.begin();
while ( sIt != v4.end() )
cout << *sIt++ << " ";
cout << endl;
// 拷贝构造
vector<string> v5(v4);
for ( int i=0; i<3; i++ )
cout << v5[i] << " ";
cout << endl;
return 0;
}
运行结果:
// Alex John Robert
// Alex John Robert
#include <iostream> #include <list> #include <algorithm> using namespace std; int main() { list<int> L; L.push_front(3); front_insert_iterator<list<int> > iL(L); *iL++ = 0; *iL++ = 1; *iL++ = 2; copy(L.begin(), L.end(), ostream_iterator<int>(cout, " ")); } 运行结果: // 2 1 0 3
#include <iostream> #include <vector> #include <numeric> using namespace std; int main () { vector<int> vInt(5); iota (vInt.begin(),vInt.end(),1); vector<int>::iterator It = vInt.begin(); while ( It != vInt.end() ) cout << It++ << " "; cout << ; // or for ( It = vInt.begin(); It != vInt.end(); It++ ) cout << It << " "; cout << ; return 0; } 运行结果: // 1 2 3 4 5 // 1 2 3 4 5