Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 向量字符串推断为什么类型?_C++_String_Vector_Type Deduction - Fatal编程技术网

C++ 向量字符串推断为什么类型?

C++ 向量字符串推断为什么类型?,c++,string,vector,type-deduction,C++,String,Vector,Type Deduction,我越来越熟悉矢量的使用(阅读),它显示了以下代码作为示例: // as with std::array, the type can be omitted since C++17 std::vector array4 { 9, 7, 5, 3, 1 }; // deduced to std::vector<int> (即标准::字符串) 不,字符串文字与类std::string无关。从技术上讲,如果vector对此有专门的推导指南,则可能会出现这种情况,但事实并非如此 …煤焦* 不,

我越来越熟悉矢量的使用(阅读),它显示了以下代码作为示例:

// as with std::array, the type can be omitted since C++17
std::vector array4 { 9, 7, 5, 3, 1 }; // deduced to std::vector<int>
(即标准::字符串)

不,字符串文字与类
std::string
无关。从技术上讲,如果vector对此有专门的推导指南,则可能会出现这种情况,但事实并非如此

…煤焦*

不,字符串文字是常量


包含的类型将被推断为
const char*

只是想添加字符串文本的类型
const char[N]
,其中N是包括终止符在内的字符数,向量的列表初始值设定项构造函数接受值而不是引用,因此文本衰减到指针
常量char*

如果需要std::strings的向量,可以使用literal
运算符“s

std::vector strArray {"Hello"s, "world"s, "!!!"s};

std::vector<std::string> strArray {"Hello", "world", "!!!"};
std::vector strArray{“你好”,“世界”,“!!!”;
std::vector<std::string> strArray {"Hello", "world", "!!!"};