如何在 C++ 中将数组划分为不同的数组
how to divide an array into different arrays in c++
>我用 c++ 编写了这段代码来将信号读取为数组,现在我需要将这个数组分段为 4 或 5 个不同的数组,以便将前 20 个元素放在 array1 中;阵列 20 中的 50-2 个,依此类推. 如何在 C++ 中执行此操作 我的代码 :
int main()
{
// first we use for loop to insert the signal as arry by the user......
int size;
cout << "this programme read your signal as array first you need to "
"determine the size of the array "
<< endl
<< " Enter desired size of the array";
cin >> size;
vector<float> sig(size);
cout << "the signal " << endl;
for (int x = 0; x < size; x++)
{
cin >> sig[x];
}
}
要使用另一个向量的子范围创建vector
,您可以使用在链接中接受两个迭代器( (5( 的构造函数(:
std::vector<float> x(100);
std::vector<flaot> y(x.begin()+begin,x.begin()+end);
y
将具有从索引begin
到end
(不包括end
(的元素副本x
。
但是,我宁愿从一开始就将元素存储在正确的位置,而不是先将它们读取到vector<float> sig(size);
中。或者,您可以考虑将所有输入保留在单个向量中,并将迭代器传递给需要使用完整信号的子范围而不是分割信号的函数。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- 如何在 C++ 中将数组划分为不同的数组
- 一个数组可以划分的最大子数组,使得不同子数组中任意两个元素的 GCD 始终为 1?
- 确定数组是否可以划分为两个子序列,每个子序列的顺序递增
- 划分有关枢轴C 的数组
- 使用特殊规则将数组划分为两个数组
- 简单的数组排序/检查 划分和征服版本
- 用getline在字符串中从文件中读取,然后将数字从int数组中的字符串划分
- 删除每个元素可以将数组中的另一个元素划分
- 使用迭代器将数组划分为大小不等的部分
- 如何将字符串划分为字符数组
- 根据条件划分数组中的元素