[SOLVED] Using variable numbers in a loop?

I want to be able to use variable numbers in a loop, same problem as posted here:

I’ve got a char array and pull data out of it in a loop and need to put this data in different variables.
From the post this looks just like what I want to do but it’s not working with Arduino IDE 1.8.9 so not sure if its supposed to work.

using namespace std;
int main()
{
  char* variables[] = { "aVar", "bVar", "cVar"};
  int values[] = { 1, 2, 3};
  map<string, int> VariablesMap;
  for(int i  = 0; i < 3 ; i ++)
  {
     VariablesMap[variables[i]] = values[i];
  }
  return 0; 
}

So at the end it looks like:

aVar = 1
bVar = 2
cVar = 3

Any tips on how I can do this?

map<string, int> VariablesMap; What is a “string”?

it’s not working

:frowning:

I’ve got a char array and pull data out of it in a loop and need to put this data in different variables.

Why not put the values in an array instead of separate variables ?

map<string, int> VariablesMap;

What is this supposed to do ?

I see the error of my ways. The example I copied from contained missing information. No wonder I couldn't get it work. Been staring at this too long :slight_smile:

I've found a solution using arrays as posted said above.