creating vector or array with different names in a loop

Hi
I'm trying to loop this
for(int i = 0; i <3; i++){
string a = "desc";
char counter1[10];
itoa(i,counter1,10);
a += counter1;// the name that should be used insted of
vector <double> a;
}
out put vectors with names of desc0, desc1 and desc2
how can I do that
thank you in advance
You can't do that. Names of variables must be known at compile time.
One way to have looping variable dependent vector identifiers might be to use a std::vector<std::unique_ptr<std::vector<double>> such that each element of this vector refers to a unique std::vector<double>:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <memory>
#include <vector>
#include <utility>

constexpr auto SIZE = 3;

int main ()
{
   std::vector<std::unique_ptr<std::vector<double>>> desc;
   for (auto i = 0; i < SIZE; ++i)
   {
       std::cout << "Enter size of vector #" << i + 1 << ": ";
       size_t n{};
       std::cin >> n;
       std::vector<double> v{};
       for (auto j = 0; j < n; ++j)
       {
           std::cout << "Enter element #" << j + 1 << " of vector# " << i + 1 << ": ";
           double num{};
           std::cin >> num;
           v.push_back(num);
        }
       desc.push_back(std::move(std::make_unique<std::vector<double>>(v)));
       v.clear();
   }
   for (auto i = 0; i < SIZE; ++i)
   {
       for (auto j = 0; j < (*desc[i]).size(); ++j)
       {
           std::cout << (*desc[i])[j] << " ";
       }
       std::cout << "\n";
   }
}

thanks a lot.
this would get the job done.
Topic archived. No new replies allowed.