C++ vector resize 后 之前保存数据是否清除(不清除)的测试用例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xin_y/article/details/86015855
#include <iostream>
using namespace std;
#include<vector>
#include<stdio.h>

int main()
{

    std::vector<int> a;
    a.push_back(10);
    a.push_back(10);
    if(a.size() <=2)
    {   
        a.resize(3);
        fprintf(stderr, "<=2\n");
    }   

    printf("%d\n", a[0]);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xin_y/article/details/86015855