c++ vector 保存指针
生活随笔
收集整理的這篇文章主要介紹了
c++ vector 保存指针
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;int main()
{vector<int*>obj;//創(chuàng)建一個向量存儲容器 intint a=2;int b=3;int c=100;obj.push_back(&a);obj.push_back(&b);obj.push_back(&c);/*for(int i=0;i<2;i++)//去掉數(shù)組最后一個數(shù)據(jù){obj.pop_back();}*/cout<<"\n"<<endl;for(int i=0;i<obj.size();i++)//size()容器中實際數(shù)據(jù)個數(shù){cout<<obj[i]<<", ";}cout<<"\n"<<endl;for(int i=0;i<obj.size();i++)//size()容器中實際數(shù)據(jù)個數(shù){cout<<*obj[i]<<", ";}cout<<"\n"<<endl;return 0;
}
0x7fff6f00db04, 0x7fff6f00db08, 0x7fff6f00db0c, 2, 3, 100,
總結(jié)
以上是生活随笔為你收集整理的c++ vector 保存指针的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++ string 另类写法
- 下一篇: C语言学习笔记--动态库和静态库的使用