Two quick questions please:
1) How do I declare a STL string variable that I know in advance I want to
hold 5,000 bytes? I'm using SGI STL with MS VS 6.0 C++ in case that matters.
For example, right now I am doing this:
string myLargeString;
myLargeString.r eserve(5000);
But I imagine that is not as efficient to just declaring the variable
upfront so that it has the 5000 bytes reserved.
However I can't figure out how to declare it initially as 5000 bytes. For
instance this does not work:
string myLargeString(5 000);
neither does this:
string myLargeString<5 000>;
am I missing something?
2) Also on a related note - in this case is it better (efficiency-wise) to
use reserve or resize()?
As a test I did this:
string mystr;
mystr.resize(50 00:
mystr.append("h ello");
But when I look at mystr it is empty!
However if I use reserve like this:
string mystr;
mystr.reserve(5 000):
mystr.append("h ello");
then that works and I see "hello" in mystr. So why does this not work when
first using resize instead of reserve?
Thanks!