Empty string: Difference between revisions
Content added Content deleted
Childishbeat (talk | contribs) m (Zoomscript example added.) |
|||
Line 443: | Line 443: | ||
// ... |
// ... |
||
std::string str; // a string object for an empty string |
|||
// empty string declaration |
|||
std::string str; // (default constructed) |
|||
std::string str(); // (default constructor, no parameters) |
|||
std::string str{}; // (default initialized) |
|||
std::string str(""); // (const char[] conversion) |
|||
std::string str{""}; // (const char[] initializer list) |
|||
if (str.empty()) { ... } // to test if string is empty |
if (str.empty()) { ... } // to test if string is empty |
||
Line 450: | Line 458: | ||
if (str.length() == 0) { ... } |
if (str.length() == 0) { ... } |
||
if (str == "") { ... }</lang> |
if (str == "") { ... }</lang> |
||
// make a std::string empty |
|||
str.clear(); // (builtin clear function) |
|||
str = ""; // replace contents with empty string |
|||
str = {}; // swap contents with temp string (empty),then destruct temp |
|||
std::swap(str, {}); // swap contents with empty string (empty initializer list) |
|||
// create an array of empty strings |
|||
std::string s_array[100]; // 100 initialized to "" (fixed size) |
|||
std::array<std::string, 100> arr; // 100 initialized to "" (fixed size) |
|||
std::vector<std::string>(100,""); // 100 initialized to "" (variable size, 100 starting size) |
|||
// create empty string as default parameter |
|||
void func( std::string& s = {} ); // {} generated default std:string instance |
|||
=={{header|C sharp}}== |
=={{header|C sharp}}== |