কম্পিউটার

কিভাবে C++ এ একটি ভেক্টরে একটি ভেক্টর যুক্ত করবেন?


একটি ভেক্টরে একটি ভেক্টর যুক্ত করতে কেবল ভেক্টর ইনসার্ট() পদ্ধতির মাধ্যমে করা যেতে পারে।

অ্যালগরিদম

Begin
   Declare a function show().
      Pass a constructor of a vector as a parameter within show()
      function.
      for (auto const& i: input)
         Print the value of variable i.
   Declare vect1 of vector type.
      Initialize values in the vect1.
   Declare vect2 of vector type.
      Initialize values in the vect2.
   Call vect2.insert(vect2.begin(), vect1.begin(), vect1.end()) to
   append the vect1 into vect2.
   Print “Resultant vector is:”
   Call show() function to display the value of vect2.
End.

উদাহরণ কোড

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void show(vector<int> const &input) {
   for (auto const& i: input) {
      std::cout << i << " ";
   }
}
int main() {
   vector<int> v1 = { 1, 2, 3 };
   vector<int> v2 = { 4, 5 };
   v2.insert(v2.begin(), v1.begin(), v1.end());
   cout<<"Resultant vector is:"<<endl;
   show(v2);
   return 0;
}

আউটপুট

Resultant vector is:
1 2 3 4 5

  1. কিভাবে C++ এ একটি টেক্সট ফাইলে টেক্সট যুক্ত করবেন?

  2. C++ এ ইনফারেন্স টাইপ করুন

  3. কিভাবে C++ এ একটি ভেক্টরের বিষয়বস্তু মুদ্রণ করবেন?

  4. কিভাবে C++ এ ধ্রুবক সংজ্ঞায়িত করবেন?