STL應用例項

2021-06-08 02:44:24 字數 2965 閱讀 6535

一、vector的簡單應用

#include #include int main()

std::cout << std::endl;

}return 0;

}

二、deque的簡單應用

#include #include int main()

std::cout << std::endl;

}return 0;

}

三、list的簡單應用

#include #include int main()

std::cout << std::endl;

// insert five xs into the list.

std::list::iterator start = charlist.begin();

charlist.insert(++start, 5, 'x');

// display the result.

std::cout << "resultant list: ";

for (iter = charlist.begin();

iter != charlist.end(); iter++)

return 0;

}

四、set的簡單應用

#include #include int main()

五、multiset的簡單應用

#include #include int main()

六、map的簡單應用

#include #include typedef std::mapmymap;

int main()

std::cout << std::endl;

// create the second map object.

mymap charmap2;

// populate the first map with values.

charmap2[1] = 'f';

charmap2[4] = 'i';

charmap2[2] = 'g';

charmap2[5] = 'j';

charmap2[3] = 'h';

// display the contents of the second map.

std::cout << "contents of second map: " << std::endl;

for (iter = charmap2.begin();

iter != charmap2.end(); iter++)

std::cout << std::endl;

// compare the maps.

if (charmap1 == charmap2)

std::cout << "map1 == map2";

else if (charmap1 < charmap2)

std::cout << "map1 < map2";

else if (charmap1 > charmap2)

std::cout << "map1 > map2";

return 0;

}

七、multimap的簡單應用

#include #include typedef std::multimapmymap;

int main()

std::cout << std::endl;

// create the second multimap object.

mymap charmultimap2;

// populate the second multimap with values.

charmultimap2.insert(mymap::value_type(1,'c'));

charmultimap2.insert(mymap::value_type(4,'f'));

charmultimap2.insert(mymap::value_type(2,'d'));

charmultimap2.insert(mymap::value_type(7,'e'));

charmultimap2.insert(mymap::value_type(5,'f'));

charmultimap2.insert(mymap::value_type(3,'e'));

charmultimap2.insert(mymap::value_type(6,'g'));

// display the contents of the second multimap.

std::cout << "contents of second multimap: " << std::endl;

for (iter = charmultimap2.begin();

iter != charmultimap2.end(); iter++)

std::cout << std::endl;

// compare the multimaps.

if (charmultimap == charmultimap2)

std::cout << "multimap1 == multimap2";

else if (charmultimap < charmultimap2)

std::cout << "multimap1 < multimap2";

else if (charmultimap > charmultimap2)

std::cout << "multimap1 > multimap2";

return 0;

}

STL之map學習例項

1 2 include3 include4 include5 include6 include7 include8 include9 using namespace std 1011 define sale depatment 1 銷售部門 12 define develop depatment 2...

應用例項 最新電工電路應用例項

電工學習網 www.diangon.com 最新電工電路應用例項 是根據最新國家職業標準,結合生產實際,以操作技能為主,以解決實際工作中的技術問題為目標而編寫的。本書的主要內容包括 照明 配電及單相電動機電路,電動機典型控制電路,電動機保護電路,工具機控制電路,穩壓電路及充電電路,電氣測量電路,pl...

mysql 應用例項 MySQL多例項應用

國內映象 2.上傳 解壓 tar xf mysql 5.6.46 linux glibc2.12 x86 64.tar.gz tar xf mysql 5.7.12 linux glibc2.12 x86 64.tar.xz tar xf mysql 8.0.18 linux glibc2.12 x...