锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久99国产精品成人欧美,国产精品久久久久免费a∨,久久99精品久久久久子伦http://www.shnenglu.com/izualzhy/category/15346.html鍧氭寔 鐩鎬俊鑷繁zh-cnTue, 15 Nov 2011 01:40:55 GMTTue, 15 Nov 2011 01:40:55 GMT60C++ iostream榪唬鍣ㄧ畝浠?1)http://www.shnenglu.com/izualzhy/archive/2011/11/09/159894.htmlizualzhyizualzhyWed, 09 Nov 2011 15:15:00 GMThttp://www.shnenglu.com/izualzhy/archive/2011/11/09/159894.htmlhttp://www.shnenglu.com/izualzhy/comments/159894.htmlhttp://www.shnenglu.com/izualzhy/archive/2011/11/09/159894.html#Feedback0http://www.shnenglu.com/izualzhy/comments/commentRss/159894.htmlhttp://www.shnenglu.com/izualzhy/services/trackbacks/159894.html鏍囧噯搴撳畾涔夌殑榪唬鍣ㄦ湁寰堝縐嶏紝istream_iterator鐢ㄤ簬璇誨彇杈撳叆嫻侊紝 ostream_iterator鐢ㄤ簬鍐欒緭鍑烘祦銆傝繖浜涜凱浠e櫒灝嗗畠浠墍瀵瑰簲鐨勬祦瑙嗕負鐗瑰畾綾誨瀷鐨勫厓绱犲簭鍒椼備嬌鐢ㄦ祦榪唬鍣ㄦ椂錛屽彲浠ョ敤娉涘瀷綆楁硶浠庢祦瀵硅薄璇誨彇鏁版嵁錛堟垨灝嗘暟鎹啓鍒版祦瀵硅薄錛夈?

榪欑瘒絎旇涓昏鏄叾瀹氫箟鍜屽熀鏈殑浣跨敤錛?

iostream榪唬鍣ㄧ殑鏋勯犲嚱鏁幫細

1. istream_iterator<T> in(strm);

鍒涘緩浠庤緭鍏ユ祦strm璇誨彇T綾誨瀷瀵硅薄鐨刬stream_iterator瀵硅薄

2. istream_iterator<T> in;

istream_iterator瀵硅薄鐨勮秴鍑烘湯绔凱浠e櫒銆?

3. ostream_iterator<T> out(strm);

鍒涘緩灝員綾誨瀷鐨勫璞″啓鍒拌緭鍑烘祦strm鐨刼stream_iterator瀵硅薄

4. ostream_iterator<T> out(strm,delim);

鍒涘緩灝員綾誨瀷鐨勫璞″啓鍒拌緭鍑烘祦strm鐨刼stream_iterator瀵硅薄錛屽湪鍐欏叆榪囩▼涓嬌鐢╠elim浣滀負鍏冪礌鐨勫垎闅旂銆俤elim鏄互絀哄瓧絎︾粨鏉熺殑瀛楃鏁扮粍銆?

鍏堢湅istream_iterator涓涓緥瀛愶細

#include <iostream>

#include <vector>

#include <iterator>

using namespace std;

int main()

{

istream_iterator<int> cin_it(cin);//read ints from cin

istream_iterator<int> end_of_stream;//end iterator value(eof)

vector<int> vec(cin_it, end_of_stream);

//also should be written like this:

//vector<int> vec;

//while (cin_it != end_of_stream)

//vec.push_back(*cin_it++);

vector<int>::iterator it=vec.begin();

while (it!=vec.end()) {

cout << " " << *it++;

}

cout << endl;

return 0;

}


璇ョ▼搴忚鍙栭敭鐩樿緭鍏ワ紝鍐欏埌vec錛岀洿鍒伴亣鍒伴潪娉曡緭鍏ャ傚儚涓嬮潰榪欐牱錛?

1 2 3 4af

1 2 3 4

紼嬪簭寰幆浠巆in璇誨彇int鍨嬫暟鎹紝騫跺皢璇誨叆鐨勫唴瀹逛繚瀛樺湪vec銆傛瘡嬈″驚鐜兘浼氭鏌in_it鏄惁涓篹of銆傚叾涓璭of榪唬鍣ㄥ畾涔変負絀虹殑istream_iterator瀵硅薄錛岀敤浣滅粨鏉熻凱浠e櫒銆傜粦鍦ㄦ祦涓婄殑榪唬鍣ㄥ湪閬囧埌鏂囦歡鎴栨煇涓敊璇椂錛屽皢絳変簬緇撴潫榪唬鍣ㄧ殑鍊箋?

濡傜▼搴忔敞閲婇噷鐨勶紝榪欓儴鍒嗗彲浠ョ敤

vector<int> vec(cin_it, end_of_stream)//construct vec from an iterator range

鏉ヤ唬鏇褲?

榪欓噷錛岀敤涓瀵規爣璁板厓绱犺寖鍥寸殑榪唬鍣ㄦ瀯閫爒ec瀵硅薄銆傝繖浜涜凱浠e櫒鏄痠stream_iterator瀵硅薄錛岃繖灝辨剰鍛崇潃榪欐鑼冨洿鐨勫厓绱犳槸閫氳繃璇誨彇鎵鍏寵仈鐨勬祦鏉ヨ幏寰楃殑銆傝繖涓瀯閫犲嚱鏁扮殑鏁堟灉鏄cin錛岀洿鍒板埌杈炬枃浠剁粨鏉熸垨杈撳叆鐨勪笉鏄痠nt鍨嬫暟鍊間負姝€傝鍙栫殑鍏冪礌鐢ㄤ簬鏋勯爒ec瀵硅薄銆?

鍦ㄥ垱寤篿stream_iterator鏃訛紝鍙洿鎺ュ皢瀹冪粦瀹氬埌涓涓祦涓娿傚彟涓縐嶆柟娉曟槸鍒涘緩鏃朵笉鎻愪緵瀹炲弬錛屽垯璇ヨ凱浠e櫒鎸囧悜瓚呭嚭鏈鐨勪綅緗俹stream_iterator涓嶆彁渚涜秴鍑烘湯绔凱浠e櫒銆?

ostream_iterator瀵硅薄蹇呴』涓庣壒瀹氱殑嫻佺粦鍦ㄤ竴璧楓傚湪鍒涘緩ostream_iterator鏃訛紝鍙彁渚涚浜屼釜錛堝彲閫夌殑錛夊疄鍙傦紝鎸囧畾灝嗗厓绱犲啓鍏ヨ緭鍑烘祦鏃朵嬌鐢ㄧ殑鍒嗛殧絎︺傚垎闅旂蹇呴』鏄疌椋庢牸瀛楃涓層傚洜涓哄畠鏄疌椋庢牸瀛楃涓詫紝鎵浠ュ繀欏諱互絀哄瓧絎︾粨鏉燂紱鍚﹀垯錛屽叾琛屼負灝嗘槸鏈畾涔夌殑銆?

鐪嬩釜ostream_iterator鐨勪緥瀛愶細

#include <iostream>

#include <iterator>

#include <string>

using namespace std;

int main()

{

ostream_iterator<string> out_iter(cout, ":test\n");//write one string per line to the standard output

istream_iterator<string> in_iter(cin),eof;//read strings from standard input and the end iterator

while (in_iter!=eof) {

//write value of in_iter to standard output

//and then increment the iterator to get the next value from cin

*out_iter = *in_iter;//write to standard output here

++out_iter;

++in_iter;

}

return 0;

}


榪欎釜紼嬪簭璇籧in錛屽茍灝嗘瘡涓鍏ョ殑鍊間緷嬈″啓鍒癱out涓嶅悓鐨勮銆?

棣栧厛錛屽畾涓涓猳stream_stream瀵硅薄錛岀敤浜庡皢string綾誨瀷鐨勬暟鎹啓鍒癱out涓紝姣忎釜string瀵硅薄鍚庤窡涓涓?#8221;test”鍜屾崲琛岀銆傚畾涔変袱涓猧stream_iterator瀵硅薄錛岀敤浜庝粠cin涓鍙杝tring瀵硅薄銆倃hile寰幆綾諱技浜庡墠涓涓緥瀛愩備絾鏄繖涓嬈′笉鏄皢璇誨彇鐨勬暟鎹瓨鍌ㄥ湪vector瀵硅薄錛岃屾槸灝嗚鍙栫殑鏁版嵁浠樼粰out_iter,浠庤岃緭鍑哄埌cout涓娿?

*out_iter = *in_iter;榪欎竴鍙ユ墽琛屾椂錛屼細鍚慶onsole鎵撳嵃銆?

杈撳嚭綾諱技浜庤繖涓牱瀛愶細

123

123:test

abc

abc:test

xyz

xyz:test

鍙傝冿細

1. 銆奀++Primer銆?

izualzhy 2011-11-09 23:15 鍙戣〃璇勮
]]>
STL-Algorithm涔媐or_each鍑芥暟瀛︿範http://www.shnenglu.com/izualzhy/archive/2011/11/09/159891.htmlizualzhyizualzhyWed, 09 Nov 2011 15:09:00 GMThttp://www.shnenglu.com/izualzhy/archive/2011/11/09/159891.htmlhttp://www.shnenglu.com/izualzhy/comments/159891.htmlhttp://www.shnenglu.com/izualzhy/archive/2011/11/09/159891.html#Feedback0http://www.shnenglu.com/izualzhy/comments/commentRss/159891.htmlhttp://www.shnenglu.com/izualzhy/services/trackbacks/159891.html鏈榪戝涔犱竴鏈珻++ Library Reference鐨勭數瀛愪功錛屾劅瑙夎窡緲誨瓧鍏鎬技鐨勶紝鏈枃鏄妱褰曚笅鏉ョ殑瀛︿範絎旇涔嬩竴銆?

鍑芥暟澹版槑錛?/p>

template<class InputInterator, class Function>

Function for_each(InputIterator first, InputIterator last, Function f);

鍑芥暟瑙i噴錛?

瀵瑰叾杈撳叆鑼冨洿[first,last)鐨勬瘡涓涓厓绱犲簲鐢ㄥ嚱鏁幫紙鎴栧嚱鏁板璞★級f銆傚鏋渇鏈夎繑鍥炲鹼紝灝卞拷鐣ヨ榪斿洖鍊箋傝凱浠e櫒鏄緭鍏ヨ凱浠e櫒錛屾墍浠涓嶈兘鍐欏厓绱犮?

鍑芥暟琛屼負綾諱技浜庤繖鏍鳳細

template<class InputIterator, class Function>

Function for_each(InputIterator first, InputIterator last, Function f)

{

while (first!=last)

f(*first++);

return f;

}

鍏充簬f鐨勫畾涔夛細

Unary function taking an element in the range as argument. This can either be a pointer to a function or an object whose class overloads operator().
Its return value, if any, is ignored.

渚嬪瓙錛?/p>

//for_each example

#include <iostream>

#include <algorithm>

#include <vector>

using namespace std;

void myfunction(int i)

{

cout << "myfunction: " << i << endl;

}

struct myclass

{

void operator()(int i) { cout << "myclass: " << i << endl; }

}myobject;

int main()

{

vector<int> myvector;

myvector.push_back(10);

myvector.push_back(20);

myvector.push_back(30);

cout << "myvector contains: " << endl;

for_each(myvector.begin(),myvector.end(),myfunction);

cout << "myvector contains: " << endl;

for_each(myvector.begin(),myvector.end(),myobject);

return 0;

}


杈撳嚭錛?

myvector contains:

myfunction: 10

myfunction: 20

myfunction: 30

myvector contains:

myclass: 10

myclass: 20

myclass: 30

izualzhy 2011-11-09 23:09 鍙戣〃璇勮
]]>
[杞琞鍏充簬STL-map璁茬殑寰堜笉閿欑殑涓綃囨枃绔?/title><link>http://www.shnenglu.com/izualzhy/archive/2011/10/20/158783.html</link><dc:creator>izualzhy</dc:creator><author>izualzhy</author><pubDate>Thu, 20 Oct 2011 14:24:00 GMT</pubDate><guid>http://www.shnenglu.com/izualzhy/archive/2011/10/20/158783.html</guid><wfw:comment>http://www.shnenglu.com/izualzhy/comments/158783.html</wfw:comment><comments>http://www.shnenglu.com/izualzhy/archive/2011/10/20/158783.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/izualzhy/comments/commentRss/158783.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/izualzhy/services/trackbacks/158783.html</trackback:ping><description><![CDATA[<p><font color="#ff0000"><strong>涓錛歮ap鏄叧鑱斿紡瀹瑰櫒錛屽畠鎻愪緵涓瀵逛竴鐨勬槧灝?/strong></font>銆傚瓨鍌ㄧ殑鏁版嵁鏈変袱涓儴鍒嗭紝涓涓槸鍏抽敭瀛楋紝涓涓槸鍊鹼紝鍏朵腑鍏抽敭瀛楀彧鑳藉嚭鐜頒竴嬈★紝鑰屼笉鍚岀殑鍏抽敭瀛楋紝鍙互鏈夌浉鍚岀殑鍊箋俶ap涓敤pair鏉ュ瓨鍌ㄨ繖涓や釜鍊肩殑銆俻air鏄痵tl瀹氫箟鐨勪竴縐嶆暟鎹粨鏋勶紝鍚庨潰浼氭湁綆榪般俶ap鍐呴儴鑷緩涓棰楃孩榛戞爲錛屾墍鏈塵ap閲岄潰鐨勬暟鎹兘鏄湁搴忕殑銆?<p><font color="#ff0000"><strong>浜岋細鏂規硶</strong></font> <p><b>1.</b><b>鏋勯犲嚱鏁?/b>錛宮ap鏈?涓瀯閫犲嚱鏁般備絾鏄垜浠氬父鐢╩ap<type1,type2> m;榪欑鏂規硶鏉ユ瀯閫犱竴涓猰ap瀹炰緥銆?<p><b>2.</b><b>鏁版嵁鎻掑叆</b>錛宮ap閫氬父鐢ㄤ笅闈㈢殑涓夌鏂瑰紡鎻掑叆鏁版嵁銆?<p>1),鐢╥nsert鏂規硶鎻掑叆pair鏁版嵁銆?/p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 1: <span style="color: #0000ff">void</span> main( VOID ) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 2: { </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 3: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>> m; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 4: m.insert(pair<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>("<span style="color: #8b0000">sa</span>",67)); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 5: m.insert(make_pair<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>("<span style="color: #8b0000">sd</span>",565));<span style="color: #008000">//鐢╩ake_pair鏂規硶(鍑芥暟)浜х敓pair瀵硅薄銆?/span> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 6: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::iterator it = m.begin(); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 7: <span style="color: #0000ff">while</span>(it!=m.end()) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 8: { </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 9: cout<<it->first<<"<span style="color: #8b0000"> </span>"<<it->second<<endl; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 10: it++; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 11: } </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 12: }</pre></pre> <p>2,)鐢╥nsert鍑芥暟鎻掑叆value_type鏁版嵁銆?/p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 1: <span style="color: #0000ff">void</span> main( VOID ) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 2: { </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 3: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>> m; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 4: m.insert(map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::value_type("<span style="color: #8b0000">sd</span>",5)); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 5: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::iterator it = m.begin(); </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 6: <span style="color: #0000ff">while</span>(it!=m.end()) </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 7: { </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 8: cout<<it->first<<"<span style="color: #8b0000"> </span>"<<it->second<<endl; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 9: it++; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 10: } </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 11: }</pre></pre> <p>鍏跺疄榪欎釜鏂規硶鍜屼笂闈㈢殑鏈川涓婃槸涓鏍風殑銆傚洜涓簐alud_type 灝辨槸pair綾誨瀷鐨勶紝鍙槸鎹釜鏂規硶鑰屽凡錛屽彲浠ラ氳繃 cout<<typeid(map<string,int>::value_type).name()鏉ヨ幏寰?value_type鐨勭被鍨嬶紝寰楀埌綾誨瀷涓? <p>struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,int>璇存槑鏄釜struct pair綾誨瀷鐨勩? <p>3,)閫氳繃閲嶈澆[]鏉ユ彃鍏ユ暟鎹?/p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 1: <span style="color: #0000ff">void</span> main( VOID ) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 2: { </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 3: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>> m; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 4: cout<<typeid(map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::value_type).name()<<endl; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 5: m["<span style="color: #8b0000">ds</span>"] = 4; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 6: m["<span style="color: #8b0000">ds</span>"] = 10; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 7: map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::iterator it = m.begin(); </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 8: <span style="color: #0000ff">while</span>(it!=m.end()) </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 9: { </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 10: cout<<it->first<<"<span style="color: #8b0000"> </span>"<<it->second<<endl; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 11: it++; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 12: } </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 13: }</pre></pre> <p>榪欑娉曞紡鏄氳繃閲嶈澆[]鏉ュ疄鐜扮殑錛屼絾鏄渶瑕佹敞鎰忕殑鏄紝榪欑娉曞紡鍜屽墠涓ょ鏈夋湰璐ㄧ殑鍖哄埆錛岀湅涓嬮潰鐨勪唬鐮? <p>m.insert(pair<string,int>("ds",5)); <p>m.insert(pair<string,int>("ds",15)); <p>褰撳叧閿瓧鐩稿悓鐨勬椂鍊欙紝涓嶄細鏀瑰彉浠栫殑鍊鹼紝涔熷氨鏄鍦ㄨ皟鐢╥nsert鍑芥暟鐨勬椂鍊欙紝浼氭鏌ワ紝榪欎釜鍏抽敭瀛楁槸鍚﹀瓨鍦ㄤ簡錛屽鏋滃瓨鍦紝閭d箞灝變笉鍋氫換浣曟搷浣溿傚惁鍒欐彃鍏ユ柊鐨勬暟鎹? <p>m["ds"] = 4; <p>m["ds"] = 10; <p>榪欑鏂瑰紡鎻掑叆鏁版嵁鏄笉浼氬仛媯鏌ョ殑錛屼細鐩存帴鍦ㄩ偅涓偣涓婂啓涓婂叧閿瓧鍜屽鹼紝涔熷氨鏄銆俤s欏圭殑鍊煎皢鏄?0. <p><b>3</b><b>錛屾暟鎹亶鍘嗐?/b> <p>stl閲岀殑瀹瑰櫒鐨勯亶鍘嗛兘鏄氳繃榪唬鍣ㄦ潵閬嶅巻鐨勩傚嵆渚挎槸鐢ㄦ暟緇勭殑鏂瑰紡錛屼篃鏄氳繃榪唬鍣ㄣ傛暟鎹亶鍘嗕篃鏈変笁縐嶆硶寮忥紝1錛屽悜鍓嶈凱浠e櫒錛?錛岀敤鍙嶅悜榪唬鍣紝3錛屾暟緇勶紝絎竴縐嶆柟寮忓墠闈篃灝辨湁璇存槑銆備笅闈㈣絎簩絎笁縐嶏紝 <p>鍙嶅悜榪唬鍣ㄧ殑鏂瑰紡銆? <p>榪欐牱鏄互鐩稿弽鐨勬硶寮忚緭鍑虹殑銆? <p>鏁扮粍鏂瑰紡</p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">void</span> main( VOID ) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{ </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>> m; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">m["<span style="color: #8b0000">ds</span>"] = 4; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">m["<span style="color: #8b0000">as</span>"] = 10; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">m.insert(pair<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>("<span style="color: #8b0000">cs</span>",5)); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">m["<span style="color: #8b0000">bs</span>"] = 123; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::iterator it = m.begin(); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">for</span>(<span style="color: #0000ff">int</span> i=1;i<=m.size();i++) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{ </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout<<m[it->first]<<endl;<span style="color: #008000">//榪欓噷鏄敤閲嶈澆[]鏉ュ緱鍒皏alue鐨勩?/span> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">it++; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">} </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}</pre></pre> <p><b>4 .</b><b>鏁版嵁鐨勬煡鎵撅紙鍖呮嫭鍒ゅ畾榪欎釜鍏抽敭瀛楁槸鍚﹀湪map</b><b>涓嚭鐜幫級</b> <p>鍦ㄨ繖閲屾垜浠皢浣撲細錛宮ap鍦ㄦ暟鎹彃鍏ユ椂淇濊瘉鏈夊簭鐨勫ソ澶勩? <p>瑕佸垽瀹氫竴涓暟鎹紙鍏抽敭瀛楋級鏄惁鍦╩ap涓嚭鐜扮殑鏂規硶姣旇緝澶氾紝榪欓噷鏍囬铏界劧鏄暟鎹殑鏌ユ壘錛屽湪榪欓噷灝嗙┛鎻掔潃澶ч噺鐨刴ap鍩烘湰鐢ㄦ硶銆? <p>榪欓噷緇欏嚭涓?2)縐嶆暟鎹煡鎵炬柟娉? <p>絎竴縐嶏細鐢╟ount鍑芥暟鏉ュ垽瀹氬叧閿瓧鏄惁鍑虹幇錛屽叾緙虹偣鏄棤娉曞畾浣嶆暟鎹嚭鐜頒綅緗?鐢變簬map鐨勭壒鎬э紝涓瀵逛竴鐨勬槧灝勫叧緋伙紝灝卞喅瀹氫簡count鍑芥暟鐨勮繑鍥炲煎彧鏈変袱涓紝瑕佷箞鏄?錛岃涔堟槸1錛屽嚭鐜扮殑鎯呭喌錛屽綋鐒舵槸榪斿洖1浜? <p>絎簩縐嶏細鐢╢ind鍑芥暟鏉ュ畾浣嶆暟鎹嚭鐜頒綅緗紝瀹冭繑鍥炵殑涓涓凱浠e櫒錛屽綋鏁版嵁鍑虹幇鏃訛紝瀹冭繑鍥炴暟鎹墍鍦ㄤ綅緗殑榪唬鍣紝濡傛灉map涓病鏈夎鏌ユ壘鐨勬暟鎹紝瀹冭繑鍥炵殑榪唬鍣ㄧ瓑浜巈nd鍑芥暟榪斿洖鐨勮凱浠e櫒</p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <iostream> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <fstream> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <<span style="color: #0000ff">string</span>> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <map> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">void</span> main() </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{ </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//瀹氫箟map 瀵硅薄</span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>> word; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//瀹氫箟鎸囬拡</span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::iterator it; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//鍚憌ord 鎻掑叆鍏冪礌 ("a",9)</span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">word.insert (map<<span style="color: #0000ff">string</span>,<span style="color: #0000ff">int</span>>::value_type("<span style="color: #8b0000">a</span>",9)); </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//鏌ユ壘 閿槸"a"鐨勫厓绱狅紝榪斿洖鎸囧悜鍏冪礌鐨勬寚閽堛?/span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">it=word.find ("<span style="color: #8b0000">a</span>"); </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//濡傛灉鍏冪礌涓嶅瓨鍦紝鎸囬拡鎸囧悜word.end().</span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">if</span>(it!=word.end ()) </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout<<it->second<<endl; <span style="color: #008000">//杈撳嚭鍏冪礌鐨勫?/span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//鏌ユ壘 閿槸"a"鐨勫厓绱狅紝</span> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">int</span> result=word.count ("<span style="color: #8b0000">a</span>"); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">//濡傛灉閿瓨鍦ㄨ繑鍥?錛屽惁鍒欒繑鍥?</span> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">if</span>(result) </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout<<word["<span style="color: #8b0000">a</span>"]<<endl; <span style="color: #008000">//杈撳嚭鍏冪礌鐨勫?/span> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout<<endl; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}</pre></pre> <p><b>5.</b><b>鏁版嵁娓呯┖錛屾垨鍒ょ┖錛?/b> <p>娓呯┖鏁版嵁鐢╟lear鍑芥暟錛屽垽鏂暟鎹槸鍚︽槸絀虹敤empty鍑芥暟銆? <p><b>6.</b><b>鏁版嵁鍒犻櫎銆?/b> <p>鏁版嵁鍒犻櫎鐢╡rase鍑芥暟錛岃繖涓嚱鏁版湁3涓噸杞藉嚱鏁幫紝鐢ㄧ殑鏃跺欙紝鍙殢鏈鴻岀敤銆傛敞鎰忕敤榪欎釜鍑芥暟鍚庯紝鐩稿叧鐨勮凱浠e櫒灝嗕細澶辨晥銆? <p><font color="#ff0000"><strong>涓夛細pair鏄痵tl閲?鐩墠鎴戠煡閬撶殑)瀹氫箟鐨勪竴涓猻truct</strong>錛?/font>鍦╩sdn涓婃煡鍒板涓嬬殑淇℃伅銆? <p>template<class Type1, class Type2> <p>struct pair <p>{ <p>typedef Type1 first_type; <p>typedef Type2 second_type <p>Type1 first; <p>Type2 second; <p>pair( ); <p>pair( <p>const Type1& __Val1, <p>const Type2& __Val2 <p>); <p>template<class Other1, class Other2> <p>pair( <p>const pair<Other1, Other2>& _Right <p>); <p>涓庝箣鐩稿叧鐨勬槸make_pair鍑芥暟銆傛槸涓ā鏉垮嚱鏁般? <p>template<class Type1, class Type2> pair<Type1, Type2> make_pair( Type1 _Val1, Type2 _Val2 ); <p><strong><font color="#ff0000">鍥涳細鍏充簬map鐨勮凱浠e櫒錛?/font></strong> <p>瀵規暟鎹殑鎻掑叆錛岄亶鍘嗭紝鏌ユ壘絳夋搷浣滐紝榪唬鍣ㄥ皢涓嶄細澶辨晥錛屼絾鏄垹闄ゆ搷浣滀細澶辨晥銆傝繖涓巚ector絳夊簭鍒楀紡瀹瑰櫒鏄笉涓鏍風殑銆? <p><font color="#ff0000"><strong>浜旓細鏁堢巼</strong></font> <p>鍥犱負鍐呴儴RB-TREE鎵浠ュぇ澶氭暟鐨勬搷浣滅殑鏃墮棿澶嶆潅搴﹂兘鏄疧(logN)錛岀┖闂村垎鏋愶紝鍦ㄨ繖浜涜妭鐐逛笉淇濆瓨鏁版嵁鐨勬儏鍐典笅灝遍渶瑕侊紝宸﹀彸瀛╁瓙鎸囬拡錛屾寚鍚戠埗鑺傜偣鐨勬寚閽堬紝璇存槑綰㈤粦鐨勬灇涓懼箋? <p><font color="#ff0000"><strong>鍏細map鐨刱ey鐨勬瘮杈冿細</strong></font> <p>value_compare value_comp ( ) const; <p>鍏惰繑鍥炲兼槸涓涓瘮杈冪被鐨勫璞★紝榪欎釜綾繪槸map::value_compare錛屽茍涓旀槸map鐨勪竴涓唴閮ㄧ被銆? <p>榪斿洖鐨勮繖涓璞″彲浠ョ敤鏉ラ氳繃姣旇緝涓や釜鍏冪礌鐨剉alue鏉ュ垽鍐沖畠浠搴旂殑key鍦╩ap鐨勪綅緗皝鍦ㄥ墠闈㈣皝鍦ㄥ悗闈€? <p>涓嬮潰鏄竴涓畝鍗曠殑渚嬪瓙錛岀湅涓涓嬪氨浼氭洿鏄庣櫧浜?</p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <iostream> </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">#include <map> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">int</span> main () </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">{ </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">char</span>,<span style="color: #0000ff">int</span>> mymap; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">map<<span style="color: #0000ff">char</span>,<span style="color: #0000ff">int</span>>::iterator it; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">pair<<span style="color: #0000ff">char</span>,<span style="color: #0000ff">int</span>> highest; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">mymap['x']=1001; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">mymap['y']=2002; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">mymap['z']=3003; </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout << "<span style="color: #8b0000">mymap contains:\n</span>"; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">highest=*mymap.rbegin(); <span style="color: #008000">// last element</span> </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">it=mymap.begin(); </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">do</span> { </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">cout << (*it).first << "<span style="color: #8b0000"> => </span>" << (*it).second << endl; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">} <span style="color: #0000ff">while</span> ( mymap.value_comp()(*it++, highest) ); </pre><pre style="background-color: #c0c0c0; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">return</span> 0; </pre><pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}</pre></pre> <p>杈撳嚭緇撴灉: <p>mymap contains: <p>x => 1001 <p>y => 2002 <p>z => 3003 <p>瑙i噴涓涓嬶紝涓婇潰璇彞while閲岄潰鐨刴ymap.value_comp()(*it++, highest)鍦ㄨ繖鏍風殑鏉′歡涓嬩細榪斿洖true: <p>*it++瀵瑰簲鐨刱ey鍦╩ap涓帓鍦╤ighest瀵瑰簲鐨刱ey鐨勫墠闈㈡椂銆?/p><img src ="http://www.shnenglu.com/izualzhy/aggbug/158783.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/izualzhy/" target="_blank">izualzhy</a> 2011-10-20 22:24 <a href="http://www.shnenglu.com/izualzhy/archive/2011/10/20/158783.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍏充簬size_t涓巗ize_typehttp://www.shnenglu.com/izualzhy/archive/2011/10/18/158636.htmlizualzhyizualzhyTue, 18 Oct 2011 14:40:00 GMThttp://www.shnenglu.com/izualzhy/archive/2011/10/18/158636.htmlhttp://www.shnenglu.com/izualzhy/comments/158636.htmlhttp://www.shnenglu.com/izualzhy/archive/2011/10/18/158636.html#Feedback0http://www.shnenglu.com/izualzhy/comments/commentRss/158636.htmlhttp://www.shnenglu.com/izualzhy/services/trackbacks/158636.html闂璧鋒簮浜庤繖鏍蜂竴孌典唬鐮侊細

01 #include <algorithm>
02 #include <stdio.h>
03
04 int main()
05 {
06 聽聽聽 size_t indexs = -1;
07 聽聽聽 size_t ps = 100;
08 聽聽聽 int index = -1;
09 聽聽聽 int p = 100;
10 聽聽聽 printf("%d\n",std::min(p,index));
11 聽聽聽 printf("%d\n",std::min(ps,indexs));
12 聽聽聽 return 0;
13 }

鍏跺疄鏄緢綆鍗曠殑棰樼洰錛屼笉榪囪瀵箂ize_t綾誨瀷鏈変竴涓簡瑙f墠琛屻?

鍏充簬size_t鐨勬潵婧?/strong>錛?

鏁版嵁綾誨瀷"socklen_t"鍜宨nt搴旇鍏鋒湁鐩稿悓鐨勯暱搴︺傚惁鍒欏氨浼氱牬鍧?BSD濂楁帴瀛楀眰鐨勫~鍏?POSIX寮濮嬬殑鏃跺欑敤鐨勬槸size_t, Linus Torvalds(浠栧笇鏈涙湁鏇村鐨勪漢,浣嗘樉鐒朵笉鏄緢澶? 鍔姏鍚戜粬浠В閲婁嬌鐢╯ize_t鏄畬鍏ㄩ敊璇殑,鍥犱負鍦?4浣嶇粨鏋勪腑 size_t鍜宨nt鐨勯暱搴︽槸涓嶄竴鏍風殑,鑰岃繖涓弬鏁?涔熷氨鏄痑ccept鍑芥暟鐨勭涓夊弬鏁?鐨勯暱搴﹀繀欏誨拰int涓鑷?鍥犱負榪欐槸BSD濂楁帴瀛楁帴鍙f爣鍑?鏈緇圥OSIX鐨勯偅甯浼欐壘鍒頒簡瑙e喅鐨勫姙娉?閭e氨鏄垱閫犱簡涓涓柊鐨勭被鍨?socklen_t".Linux Torvalds璇磋繖鏄敱浜庝粬浠彂鐜頒簡鑷繁鐨勯敊璇絾鍙堜笉濂芥剰鎬濆悜澶у浼欏効鎵胯,鎵浠ュ彟澶栧垱閫犱簡涓涓柊鐨勬暟鎹被鍨?銆?

size_t鍦–璇█涓氨鏈変簡錛宻ize_t鍜宻size_t鏄疉NSI C鎻愪緵鐨勬爣鍑嗗ご鏂囦歡閲屽畾涔夌殑涓涓?鏁版嵁綾誨瀷"錛屽叾瀹炲茍涓嶆槸鏂扮殑鏁版嵁綾誨瀷錛屼笉鏄叧閿瓧錛屾槸閫氳繃typedef浠庡凡鏈夋暟鎹被鍨嬪畾涔夎屾潵銆?

ANSI C鎬誨叡鎻愪緵浜?4涓ご鏂囦歡銆?

<cstddef>閲岃繖涔堝畾涔変簡

#include <stddef.h>

using ::size_t

using::ptrdiff_t

鍦?usr/lib/gcc/i486-linux-gnu/4.4/include涓嬮潰

<stddef.h>閲岄潰鎴戞壘鍒頒簡榪欎箞鍑犲彞錛?

#ifndef __SIZE_TYPE__

#define __SIZE__TYPE__ long unsigned int

#endif

#if !(defined(__GUNU__) && defined (size_t))

typedef __SIZE_TYPE__ size_t;

#ifdef __BEOS

typedef long ssize_t

鈥?

娌″お鐪嬫槑鐧斤紝涓嶈繃浠庣綉涓婃壘鍒頒簡涓嶉敊鐨勪竴涓?strong>瑙i噴錛?

size_t鏄負浜嗘柟渚跨郴緇熶箣闂寸殑縐繪鑰屽畾涔夌殑銆?

鍦?2浣嶇郴緇熶笂瀹氫箟涓?unsigned int

鍦?4浣嶇郴緇熶笂瀹氫箟涓?unsigned long

鏇村噯紜殑璇存硶鏄湪32浣嶇郴緇熶笂鏄?2浣嶆棤絎﹀彿鏁村瀷

鍦?4浣嶇郴緇熶笂鏄?4浣嶆棤絎﹀彿鏁村瀷

size_t涓鑸敤鏉ヨ〃紺轟竴縐嶈鏁幫紝姣斿鏈夊灝戜笢瑗胯鎷瘋礉絳夈?

sizeof鎿嶄綔絎︾殑緇撴灉綾誨瀷鏄痵ize_t,

璇ョ被鍨嬩繚璇佽兘瀹圭撼瀹炵幇鎵寤虹珛鐨勬渶澶у璞$殑瀛楄妭澶у皬銆?

瀹冪殑鎰忎箟澶ц嚧鏄?閫備簬璁¢噺鍐呭瓨涓彲瀹圭撼鐨勬暟鎹」鐩殑涓暟鐨勬棤絎﹀彿鏁存暟綾誨瀷"銆?

鎵浠ワ紝瀹冨湪鏁扮粍涓嬫爣鍜屽唴瀛樼鐞嗗嚱鏁頒箣綾葷殑鍦版柟騫挎硾浣跨敤

ssize_t:

榪欎釜鏁版嵁綾誨瀷鐢ㄦ潵琛ㄧず鍙互琚墽琛岃鍐欐搷浣滅殑鏁版嵁鍧楃殑澶у皬銆傚畠鍜宻ize_t綾諱技錛屼絾蹇呴』鏄痵igned銆?

鍐嶆潵鐪嬩笅size_t涓巗ize_type鐨勫尯鍒?/strong>錛?

鎴戣寰楁湁涓鍙ヨ瘽鎬葷粨鐨勫緢濂斤細

size_t鏄叏灞鐨勶紝鑰宻ize_type鏄窡瀹瑰櫒鐩稿叧鐨勩?

鎵句簡涓嬬浉鍏崇殑鏂囦歡錛?

/c++/4.3/bits/stl_tree.h,stl_list.h,stl_deque.h絳夌洿鎺ヨ繖涔堝畾涔変簡

typedef size_t size_type

stl_mutiset.h鍒欒繖涔堝畾涔夌殑錛?

typedef typename _Rep_type::size_type size_type;

閭d箞size_type鍒板簳鏄竴縐嶄粈涔堟牱鐨勭被鍨嬪憿錛?

string綾葷被鍨嬪拰璁稿鍏朵粬搴撶被鍨嬮兘瀹氫箟浜嗕竴浜涢厤濂楃被鍨嬶紙companion type錛夈傞氳繃榪欎簺閰嶅綾誨瀷錛屽簱綾誨瀷鐨勪嬌鐢ㄥ氨鑳戒笌鏈哄櫒鏃犲叧銆俿ize_type灝辨槸榪欎簺閰嶅綾誨瀷涓殑涓縐嶃?

size_type琚畾涔変負涓巙nsigned鍨嬶紙unsigned int, unsigned long錛夊叿鏈夌浉鍚岀殑鍚箟錛岃屼笖鍙互淇濊瘉瓚沖澶ц兘澶熷瓨鍌ㄤ換鎰弒tring瀵硅薄鐨勯暱搴︺備負鑰屾潵浣跨敤鐢眘tring綾誨瀷瀹氫箟鐨剆ize_type綾誨瀷銆傜▼搴忓憳蹇呴』鍔犱笂浣滅敤浜庢搷浣滅鏉ヨ鏄庢墍浣跨敤鐨剆ize_type綾誨瀷鏄敱string綾誨畾涔夌殑銆?

鎴戜滑涓轟粈涔堜笉閫傜敤int鍙橀噺鏉ヤ繚瀛榮tring鐨剆ize鍛紵

浣跨敤int鍙橀噺鐨勯棶棰樻槸錛氭湁浜涙満鍣ㄤ笂鐨刬nt鍙橀噺鐨勮〃紺鴻寖鍥村お灝忥紝鐢氳嚦鏃犳硶瀛樺偍瀹為檯騫朵笉闀跨殑string瀵硅薄銆傚鍦ㄦ湁16浣峣nt鍨嬬殑鏈哄櫒涓婏紝int綾誨瀷鍙橀噺鏈澶у彧鑳借〃紺?2767涓瓧絎︾殑string瀵硅薄銆傝岃兘瀹圭撼涓涓枃浠跺唴瀹圭殑string瀵硅薄杞繪槗灝辮兘瓚呰繃榪欎釜鏁板瓧錛屽洜姝わ紝涓轟簡閬垮厤婧㈠嚭錛屼繚瀛樹竴涓猻tring瀵硅薄鐨剆ize鐨勬渶瀹夊叏鐨勬柟娉曞氨鏄嬌鐢ㄦ爣鍑嗗簱綾誨瀷string錛氾細size_type().

涓鐐規敞鎰?/span>錛氳櫧鐒舵槸鍦ㄥ涔犳爣鍑嗗簱string鐨勬椂鍊欏閥閬囦簡size_type綾誨瀷錛屼絾鏄紝鍏跺疄vector搴撲篃鍙互瀹氫箟size_type綾誨瀷錛屽湪vector搴撲腑榪樻湁涓涓猟ifference_type綾誨瀷錛岃綾誨瀷鐢ㄦ潵瀛樺偍浠諱綍涓や釜榪唬鍣ㄥ璞¢棿鐨勮窛紱伙紝鎵浠ユ槸signed綾誨瀷鐨勩?

鍟板暟鍡﹀棪璇翠簡榪欎箞澶氾紝鍏跺疄鍏充簬榪欎釜闂鏂囩珷閲岀孩瀛楁爣娉ㄧ殑閮ㄥ垎灝辮凍澶熶簡銆傚叾浠栫殑鐪嬩笅鍔犳繁鍗拌薄鍗沖彲錛屾渶寮濮嬬殑紼嬪簭緇撴灉杈撳嚭涓猴細

-1 100銆?



izualzhy 2011-10-18 22:40 鍙戣〃璇勮
]]>
deque欏哄簭瀹瑰櫒http://www.shnenglu.com/izualzhy/archive/2010/11/03/132326.htmlizualzhyizualzhyWed, 03 Nov 2010 12:37:00 GMThttp://www.shnenglu.com/izualzhy/archive/2010/11/03/132326.htmlhttp://www.shnenglu.com/izualzhy/comments/132326.htmlhttp://www.shnenglu.com/izualzhy/archive/2010/11/03/132326.html#Feedback0http://www.shnenglu.com/izualzhy/comments/commentRss/132326.htmlhttp://www.shnenglu.com/izualzhy/services/trackbacks/132326.html

#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
 deque<double> values;
 ostream_iterator<double> output(cout," ");

 values.push_front(2.2);//鍙傜敤浜巐ist鍜宒eque,鑰屼笉閫備簬vector
 values.push_front(2.3);
 values.push_back(1.1);

 cout << "values contains: ";
 for ( int i=0;i<values.size();i++)
  cout << values[i] << ' ';

 values.pop_front();
 cout << "\nAfter pop_front values contains: ";
 copy(values.begin(),values.end(),output);

 values[1]=5.4;
 cout << "\nAfter values[1]=5.4 values contains: ";
 copy(values.begin(),values.end(),output);
 cout << endl;
 return 0;
}



izualzhy 2010-11-03 20:37 鍙戣〃璇勮
]]>
list欏哄簭瀹瑰櫒http://www.shnenglu.com/izualzhy/archive/2010/11/03/132302.htmlizualzhyizualzhyWed, 03 Nov 2010 09:04:00 GMThttp://www.shnenglu.com/izualzhy/archive/2010/11/03/132302.htmlhttp://www.shnenglu.com/izualzhy/comments/132302.htmlhttp://www.shnenglu.com/izualzhy/archive/2010/11/03/132302.html#Feedback0http://www.shnenglu.com/izualzhy/comments/commentRss/132302.htmlhttp://www.shnenglu.com/izualzhy/services/trackbacks/132302.html闃呰鍏ㄦ枃

izualzhy 2010-11-03 17:04 鍙戣〃璇勮
]]>
榪唬鍣ㄧ畝浠?/title><link>http://www.shnenglu.com/izualzhy/archive/2010/11/03/132285.html</link><dc:creator>izualzhy</dc:creator><author>izualzhy</author><pubDate>Wed, 03 Nov 2010 06:07:00 GMT</pubDate><guid>http://www.shnenglu.com/izualzhy/archive/2010/11/03/132285.html</guid><wfw:comment>http://www.shnenglu.com/izualzhy/comments/132285.html</wfw:comment><comments>http://www.shnenglu.com/izualzhy/archive/2010/11/03/132285.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/izualzhy/comments/commentRss/132285.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/izualzhy/services/trackbacks/132285.html</trackback:ping><description><![CDATA[     鎽樿: 鍏ラ棬鐨勪緥瀛?nbsp; <a href='http://www.shnenglu.com/izualzhy/archive/2010/11/03/132285.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/izualzhy/aggbug/132285.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/izualzhy/" target="_blank">izualzhy</a> 2010-11-03 14:07 <a href="http://www.shnenglu.com/izualzhy/archive/2010/11/03/132285.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.323r.cn" target="_blank">久久笫一福利免费导航 </a>| <a href="http://www.hf169.cn" target="_blank">久久精品国产久精国产</a>| <a href="http://www.qzlhscqt.cn" target="_blank">亚洲日本久久久午夜精品</a>| <a href="http://www.epfb.cn" target="_blank">国内精品久久久久久久涩爱</a>| <a href="http://www.outza.cn" target="_blank">精品一区二区久久</a>| <a href="http://www.qiaochaohuagong.cn" target="_blank">69久久精品无码一区二区</a>| <a href="http://www.sanling-group.com.cn" target="_blank">午夜天堂av天堂久久久</a>| <a href="http://www.aliyundjq.cn" target="_blank">亚洲中文字幕无码久久2020</a>| <a href="http://www.sqcn.com.cn" target="_blank">欧美大香线蕉线伊人久久</a>| <a href="http://www.dlhybjgs.cn" target="_blank">久久久久久久久无码精品亚洲日韩 </a>| <a href="http://www.fzmnls.cn" target="_blank">久久这里有精品视频</a>| <a href="http://www.17714.com.cn" target="_blank">精品国产综合区久久久久久</a>| <a href="http://www.j8hq8.cn" target="_blank">91精品国产综合久久香蕉</a>| <a href="http://www.domino111.com.cn" target="_blank">99久久精品免费看国产一区二区三区</a>| <a href="http://www.r3665.cn" target="_blank">久久这里只有精品久久</a>| <a href="http://www.yundali.cn" target="_blank">国产精品久久久99</a>| <a href="http://www.trademan.cn" target="_blank">亚州日韩精品专区久久久</a>| <a href="http://www.xmjbjd.cn" target="_blank">一本一本久久a久久综合精品蜜桃</a>| <a href="http://www.wubaili.com.cn" target="_blank">亚洲色婷婷综合久久</a>| <a href="http://www.ddvxo.cn" target="_blank">91精品国产乱码久久久久久</a>| <a href="http://www.onlinehotel.com.cn" target="_blank">日韩精品久久久久久</a>| <a href="http://www.numxj.cn" target="_blank">日本久久久久久久久久</a>| <a href="http://www.jumingyang.cn" target="_blank">久久亚洲私人国产精品</a>| <a href="http://www.88830.com.cn" target="_blank">久久久久中文字幕</a>| <a href="http://www.sxttzs.cn" target="_blank">久久婷婷五月综合成人D啪</a>| <a href="http://www.suichuan.net.cn" target="_blank">久久久久无码精品国产</a>| <a href="http://www.cdz8.cn" target="_blank">国产毛片久久久久久国产毛片 </a>| <a href="http://www.fangongdi.cn" target="_blank">久久天天躁狠狠躁夜夜avapp</a>| <a href="http://www.phb321.cn" target="_blank">久久人人妻人人爽人人爽</a>| <a href="http://www.zs021.cn" target="_blank">国产精品成人久久久久久久</a>| <a href="http://www.sfsqw.cn" target="_blank">久久免费看黄a级毛片</a>| <a href="http://www.su26.cn" target="_blank">久久亚洲国产精品一区二区</a>| <a href="http://www.ningxue520.cn" target="_blank">一本色道久久88综合日韩精品 </a>| <a href="http://www.vhro.cn" target="_blank">欧美久久综合性欧美</a>| <a href="http://www.jinhangroup.cn" target="_blank">久久综合日本熟妇</a>| <a href="http://www.myswiss.cn" target="_blank">2021久久国自产拍精品</a>| <a href="http://www.jsbcly.cn" target="_blank">中文字幕精品久久久久人妻</a>| <a href="http://www.yookou.cn" target="_blank">久久r热这里有精品视频</a>| <a href="http://www.xiaosp4.cn" target="_blank">免费无码国产欧美久久18</a>| <a href="http://www.dg-rx.cn" target="_blank">久久91精品综合国产首页</a>| <a href="http://www.6kun.cn" target="_blank">国产∨亚洲V天堂无码久久久</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>