Empty string: Difference between revisions

Content added Content deleted
Line 463: Line 463:
str = ""; // replace contents with empty string
str = ""; // replace contents with empty string
str = {}; // swap contents with temp string (empty),then destruct temp
str = {}; // swap contents with temp string (empty),then destruct temp

std::swap(str, {}); // swap contents with empty string (empty initializer list)
// swap with empty string
std::string tmp{}; // temp empty string
str.swap(tmp); // (builtin swap function)
std::swap(str, tmp); // swap contents with tmp



// create an array of empty strings
// create an array of empty strings