0

ユーザー入力に基づいて生成される n 個のベクトルがあります。それらを配列またはベクトルに格納したい。

私はphpから来ています.phpでは、別の配列内に配列を格納できます。C ++でこれを達成するにはどうすればよいですか。配列内またはベクトル内に n 個のベクトルを格納することによって。

// これは、php にベクトルがあると仮定して、php で実現できる方法です

    for (int i = 0 ; i< userInput ; i++)
     {
         arrayOfVectors[] =  vector<string> students_1;

      }
4

3 に答える 3

1

最も簡単な方法は、ベクトルのベクトルを使用することです。

std::vector<std::vector<string>> data (userInput);

これにより、文字列のベクトルを持つuserInputsベクトルが作成されます。これをどのように使用するかは、少なくとも PHP に不慣れな人にとっては明確ではない要件によって異なります。

于 2013-10-20T12:08:31.353 に答える
1

これを使って:

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

ブーストには多次元配列があることに注意してください

于 2013-10-20T12:09:35.273 に答える
0

何かのようなもの:

#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);
}
于 2013-10-20T12:11:18.187 に答える