在数组中存储 n 个向量
storing n numbers of vectors in array
我有n个向量,这些向量是根据用户输入生成的。我想将它们存储在数组或向量中。
我来自php,在php中,您可以将数组存储在另一个数组中。如何在 c++ 中实现这一点。通过在数组或向量内存储 n 个向量。
这在某种程度上就是在 PHP 中实现它的方式,假设 PHP 有向量
for (int i = 0 ; i< userInput ; i++)
{
arrayOfVectors[] = vector<string> students_1;
}
最简单的方法是使用向量向量:
std::vector<std::vector<string>> data (userInput);
这将创建一个包含 userInputs
个字符串向量的向量。如何使用它取决于你的要求,这些问题并不清楚,至少对于不熟悉 PHP 的人来说是不清楚的。
使用这个:
std::vector<std::vector<string>> vectors(userInput);
vectors.push_back(students_1);
vectors.push_back(students_2);
vectors.push_back(students_3);
// an so on
请注意,boost 具有多维数组
像这样:
#include<vector>
#include<string>
typedef vector<std::string> student_vector;
std::vector<student_vector> arrayOfVectors;
for(..)
{
student_vector student;
student.push_back("SomeValue");
student.push_back("SomeValue2");
arrayOfVectors.push_back(student);
}
相关文章:
- 访问存储在向量C++中的结构的多态成员
- 添加存储在向量中的大整数的函数出现问题
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 如何从用户那里获取输入并将其存储在向量中?
- 如何从文件中读取两个字符串和数字数组,并将它们存储在对象向量中
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- 在二维向量或数组中可以存储的最大元素数是多少?
- 存储在堆分配向量中的指针的免费存储
- 将相同共享指针的副本存储在不同的向量中是否是一种好的做法?
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- Sqlite3:将数据库表名存储在向量中
- 如何在数组和向量 c++ 中存储和保存输入
- C++ 将抽象类型的动态分配对象传递给函数并存储在向量中
- 代码将向量存储为向量<vector>,为什么没有错误消息?
- 替代STD ::向量存储参考而不是对象的副本
- 将向量存储在<file> CStringArray 中?
- 将可变大小结构的向量存储在c++中的二进制文件中
- 使用向量c++存储和洗牌一副牌
- 将指针向量存储在文件中并再次读取它们
- 是否可以/建议将向量存储在结构中?C++