c中未初始化的std :: string变量的值和大小

如果这样定义了一个字符串

std::string name;

未初始化的字符串“name”的值将是什么?

最佳答案
因为它没有被初始化,它是被调用的默认构造函数.然后 :

empty string constructor (default constructor) :

Constructs an empty string, with a length of zero characters.

看看:http://www.cplusplus.com/reference/string/string/string/

编辑:
如第11章第21.4.2 / 1段所述:

Effects: Constructs an object of class basic_string. The postconditions of this function are indicated in Table 63.

-> Table 63
+-----------------------------------------------------------------------------+
| data()     | a non-null pointer that is copyable and can have 0 added to it |
+------------+----------------------------------------------------------------+
| size()     | 0                                                              |
+------------+----------------------------------------------------------------+
| capacity() | an unspecified value                                            |
+-----------------------------------------------------------------------------+

转载注明原文:c中未初始化的std :: string变量的值和大小 - 代码日志