I'm developing a class for building records (with a fixed number of fields). My public methods allow the user to insert individual values by index. There's no requirement that the user fill in all fields -- so I'd like to preallocate the vector that represents the record to the exact size, with every field initialized to the empty string.
Is there a way to do this more easily than with a push-back loop?
Something like this:
std::vector<std::string> v(N);
where N is the number of strings. This creates a vector with N empty strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With