creating a serie of variables with "for" loop

Hi,

very simple question:

I have a variable

char Apple;

Now I want also Apple1, Apple2, .... Apple150 or whatever.

Is there a way to do:

1
2
for (x=1 ; x++ ; x=150)
{ "create Apple1 to Apple150" ? }


I need to do that because I need to create on the first hand an array that creates currency variables:

ex: ccy1, ccy2, ccy3, ccy4

and on the other hand a variable of character strings, "EURUSD", "USDJPY", "EURCHF"

and utimately match the first array with the second to have

ccy1 = "EURUSD"
ccy2 = "USDJPY"
ccy3 = "EURCHF"

of course I could just type the whole thing but there's not fun in that.

Your help would be very appreciated,

Regards,

Wissam
Last edited on
What you're looking for is a map:

1
2
3
4
5
6
7
8
9
10
11
12
#include <map>
[...]
map<string,string> concurrencyMap;
concurrencyMap["ccy1"]="EURUSD";
concurrencyMap["ccy2"]="USDJPY";
[...]

//or:
static const char* arrayOfSomething[]={"ccy1","ccy2"};
static const char* arrayOfSomethingElse[]={"EURUSD","USDJPY"};
const int size=sizeof(arrayOfSomething)/sizeof(*arrayOfSomething);
for (int i=0;i<size;i++)concurrencyMap[arrayOfSomething[i]]=arrayOfSomethingElse[i];
Topic archived. No new replies allowed.