Home c++ Working with C++ vectors

Working with C++ vectors

Author

Date

Category

Need help with an array of vectors. You need to specify vectors in an array of any length (the randomy of each vector). And fill each vector random numbers.

int m; m = convert :: TINT32 (NumericUpdown1- & gt; value); // Here I ask a variable and assign her value from NumericUpdown
  Vector & lt; vector & lt; int & gt; & gt; vc; // Create an array of vectors
  VC.Resize (M); // I ask the number of vectors

Answer 1, Authority 100%

# include & lt; iostream & gt;
#Include & lt; algorithm & gt;
#Include & lt; Random & GT;
Using Namespace STD;
INT MAIN ()
{
  std :: vector & lt; std :: vector & lt; int & gt; & gt; ArraySeq;
  STD :: Random_Device RD;
  STD :: MT19937 GEN (RD ());
  STD :: uniform_int_distribution & lt; & gt; SizeUID (1, 6);
  STD :: uniform_int_distribution & lt; & gt; Valueuid (-100, 100);
  STD :: SIZE_T N = SIZEUID (GEN);
  FOR (STD :: SIZE_T I = 0; I & LT; N; ++ i) {
    std :: vector & lt; int & gt; Array (SizeUID (GEN));
    Std :: Generate (Std :: Begin (Array), Std :: End (Array), [& amp] {
      RETURN VALUEUID (GEN);
    });
    arrayseq.emplace_back (STD :: Move (Array));
  }
  For (AUTO & AMP; Array: ArraySeq) {
    STD :: COUT & LT; & LT; STD :: ENDL;
    For (Const Auto & Amp; X: Array) {
      STD :: COUT & LT; & LT; x & lt; & lt; '';
    }
  }
  Return 0;
}

Descriptions used essential Looking for CPPreference.com

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions