About 218,000 results
Open links in new tab
  1. How to define a string variable in C++ - Stack Overflow

    1 Preferred string type in C++ is string, defined in namespace std, in header <string> and you can initialize it like this for example:

  2. C++ string declaration - Stack Overflow

    Nov 9, 2011 · It requires that the std::string class contains a non- explicit constructor that takes a const char *. This allows the compiler to implicitly construct a temporary std::string object.

  3. C++ String Variable Declaration - Stack Overflow

    In practical terms, this means typing string instead of std::string, cout instead of std::cout and so on. The string variable itself (in the example, the string variable is your_name) is declared with string. Let's …

  4. Declaring strings as std:string in C++ - Stack Overflow

    Apr 20, 2013 · You're declaring a label called std, and using the name string which has been dumped into the global namespace by using namespace std;. Writing it correctly as std::string, you're using …

  5. How to declare an array of strings in C++? - Stack Overflow

    Jan 28, 2016 · 1 You can directly declare an array of strings like string s[100];. Then if you want to access specific elements, you can get it directly like s[2][90]. For iteration purposes, take the size of …

  6. c++ - How can you define a static data member of type const …

    Use std::string_view for constants only if you use string_view parameters in all your functions. If any of your functions uses a const std::string& parameter, a copy of a string will be created when you pass …

  7. c++ - Declaring a string of fixed size - Stack Overflow

    Aug 22, 2016 · In C we do char buffer[100]; Is there a way to declare a fixed size std::string?

  8. What does '&' do in a C++ declaration? - Stack Overflow

    string &foo() { string localString = "Hello!"; return localString; } You would probably get some compiler errors, since you are returning a reference to a string that was initialized in the stack for that function. …

  9. c++ - Initializing strings as null vs. empty string - Stack Overflow

    Feb 5, 2015 · The default construction of std::string is not ""; it is {}. Default-constructing avoids having to check the char const*, find it is an empty string, and eventually do nothing.

  10. How do I define string constants in C++? - Stack Overflow

    Sep 27, 2011 · The OP mentions he is rusty in C++. I am merely adding some information as to how to initialize the string (put it in the cpp), that if it was an int it could be initialized directly in the class …