c++ - 在 C++ 中,如何在没有循环的情况下使用值 {1,2,...,n} 初始化 vector ?

标签 c++ vector

假设 n 是一个大整数,在 C++ 中如何在没有循环的情况下用 {1,2,...,n} 初始化一个 vector ?谢谢。

最佳答案

就这么简单:

std::vector<int> v( 123 );
std::iota( std::begin( v ), std::end( v ), 1 );

关于c++ - 在 C++ 中,如何在没有循环的情况下使用值 {1,2,...,n} 初始化 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39923968/

相关文章:

c++ - 在现代 C++ 中将 std::array<std::array<T,N>> 转换为 std::vector<T>

c++ - vector 是否比堆数组更严格地检查越界?

c++ - STL vector 中的唯一值

c++ - 如何找到将字符串转换为的正确数据类型?

c++ - 接受常量和非常量数据的通用函数及相关函数

C++/CLI Visual C++ 2010 Express - 绘制多个椭圆

c++ - 将 float 转换为 int 时的奇怪行为

c++ - 对在 Protocol Buffers 中使用 Message::ParseFromIstream 感到困惑

c++ - 在 C++ 中使用 vector 从文本文件中读取矩阵

c++ - 从模板继承非模板