相关疑难解决方法(0)

使用连续无符号整数列表初始化std :: vector <unsigned int>

我想使用一种特殊的方法来初始化一个std::vector<unsigned int>我在其中作为参考的C++书籍中描述的内容(德国着作"Ulrich Breymann的Der C++ Programmer",如果重要的话).在这本书是关于序列类型的STL的部分,特别是指list,vectordeque.在本节中,他写道,这种序列类型有两个特殊的构造函数,即,如果X引用这样的类型,

X(n, t) // creates a sequence with n copies of t
X(i, j) // creates a sequence from the elements of the interval [i, j)
Run Code Online (Sandbox Code Playgroud)

我希望使用第二个间隔unsigned int,即

std::vector<unsigned int> l(1U, 10U);
Run Code Online (Sandbox Code Playgroud)

获取初始化的列表{1,2,...,9}.然而,我得到的是一个unsigned int值为10 的向量: - | 第二个变体是否存在,如果存在,我该如何强制它被调用?

c++ stl initialization std stdvector

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

initialization ×1

std ×1

stdvector ×1

stl ×1