初始化一个向量为零C ++ / C ++ 11 [英] initialize a vector to zeros C++/C++11
本文介绍了初始化一个向量为零C ++ / C ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在C ++ 11中,他们添加了将变量初始化为零的功能。
I know in C++11 they added the feature to initialize a variable to zero as such
double number = {}; // number = 0
int data{}; // data = 0
是否有类似的方法来初始化 std: :
Is there a similar way to initialize a std::vector
of a fixed length to all zero's?
推荐答案
您不需要初始化列表:
std::vector<int> vector1(length, 0);
std::vector<double> vector2(length, 0.0);
这篇关于初始化一个向量为零C ++ / C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文