C++ STL list的大小
生活随笔
收集整理的這篇文章主要介紹了
C++ STL list的大小
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
代碼如下:
#define _SCL_SECURE_NO_WARNINGS#include <iostream> #include <algorithm> #include <list>using namespace std;struct Node{int a;char c; //如果c是0的化,控制臺顯示不了(ASCII 0 ) };void fun(Node &d){cout << d.a << " " << (int)d.c << "\n"; //"\n"比endl效率更高 }void fun1(Node &d){cout << d.a << " " << d.c << "\n"; //"\n"比endl效率更高 }int main(){Node no = { 12, 'a' };list<Node> ls(6, no);cout << ls.size() << endl;for_each(ls.begin(), ls.end(), fun1);cout << endl;ls.resize(3);cout << ls.size() << endl;for_each(ls.begin(), ls.end(), fun1);system("pause");return 0; }運行截圖如下:
總結
以上是生活随笔為你收集整理的C++ STL list的大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++ opengl 天空盒的创建
- 下一篇: Qt工作笔记-对QObject::con