Quote:Original post by TelastynQuote:Original post by nprz
I wouldn't rely on that. you are most likely going out of bounds.
cout << x.at(0) << "\n";
would changing it to that cause it to exit?
a vector might treat an int differently because storing a bunch of pointers to int would be pretty wasteful. just because it doesn't crash doesn't mean it is correct :)
Ah, yes, the change does blow it up.
It was just confusing, since I tried with ints to see if it was a problem with string use or with vector use. Since the ints worked, I spent a bunch of time trying to figure out what was wrong with elementary string use...
I have made that mistake before as well. I usually use the at function with vectors since I'd rather have it crash and be able to trace it than overwrite something it isn't supposed and keep running (although possibly abnormally).
reserve() just makes the capacity at least that size, so if you do a lot of insert it will not have to resize and copy data over and over again. resize fills the data in the vector.