dimanche 1 mars 2015

Constructing strings in loops [duplicate]



This question already has an answer here:




If a string is constructed inside of a loop



for (int i = 0; i < 10; ++i) {
std::string s = "Hi!";
// Do stuff with s ...
}


vs. constructed outside



std::string s = "Hi!";
for (int i = 0; i < 10; ++i) {
// Do stuff with s ...
}


Will there be a difference in performance? Ie. Will the string be reconstructed on each iteration of the loop?




Aucun commentaire:

Enregistrer un commentaire