If a string is defined like this
std::string name;
What will be the value of the uninitialized string "name" and what size it would be?
If a string is defined like this
std::string name;
What will be the value of the uninitialized string "name" and what size it would be?
Default constructed user-defined types are not uninitialized. The default constructor defines an empty string (i.e
""
) with a size/length of zero.value is null , and size is 0 But you can directly chk if the string is empty or not by empty()
Just in case you want to check that in your application , Do this
Similar and more detailed discussion is here initializing strings as null vs. empty string
Because it is not initialized, it is the default constructor that is called. Then :
Take a look : http://www.cplusplus.com/reference/string/string/string/
EDIT : As stated in C++11, §21.4.2/1 :
It's not uninitialized, its default constructor is called.
From http://en.cppreference.com/w/cpp/string/basic_string/basic_string:
The Standard (C++11, §21.4.2/1) describes the results of default-constructing a
std::basic_string
(of whichstd::string
is a specialization) as follows:And Table 63 says: