Your program is undefined because you access non-existing elements.
In particular, the following line has undefined behavior because item at index 4 does not yet exist.
S[4]=99;
Thus, you should read the documentation:
vector::operator[] - C++ Reference[
^]
vector::operator[
^]
In fact, just before that line get executed, you have 3 items at index 0, 1 and 2.
Given that, next line is also incorrect because you try to display items at index 3 and 4. Thus you should call
push_back
twice to add those items.
S.push_back(0); S.push_back(99);
By the way, I would recommand you to add some white space (and indentation) for readability. Here are a few example from your code that are more readable with some extra spaces:
vector<int> S;
S[4] = 99;
cout << '|' << S.at(0) << '|' << S.at(1) << '|' << S.at(2) << '|' << S.at(3) << '|' << S.at(4) << '|';
cout << endl << S.size();
return 0;