Why this program crashes? It crashes on line vec[0].assign("blabla");
:
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> vec;
vec.reserve(5);
vec[0].assign("blabla");
}
Or this:
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> vec;
vec.reserve(5);
vec[0].push_back('a');
}
And what is best to use instead of if it really doesn't work?