Q:

Explain what the following program fragment does

0

 Explain what the following program fragment does:

vector<string> svec;
svec.reserve(1024);
string word;
while (cin >> word)
 svec.push_back(word);
svec.resize(svec.size()+svec.size()/2);

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

    vector<string> svec;
    svec.reserve(1024);  // Preallocate memory for 1024 `string`s
    string word;
    while (cin >> word)  // Read stirngs into `svec`
      svec.push_back(word);
    svec.resize(svec.size()+svec.size()/2);
    // Reallocate memory, if current capacity is greater then this argument,
    // nothing happened, else expand the size to at least the same as the
    // argument.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now