dimanche 2 avril 2017

The vector has a size = 2, but it still has a value in the index 100

I run the following codes in http://cpp.sh/. The outputs show that name1.size()=2, but name1[100]=10;

// Example program
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()

{
vector<vector<int>> name;
vector <int> name1;
name1.push_back(1);
name1.push_back(3);
vector <int> name2;
name2.push_back(4);
name.push_back(name1);
name.push_back(name2);
name1[100]=10;
cout<<name1.size()<<endl;
cout<<name1[100];
}

Aucun commentaire:

Enregistrer un commentaire