Change variable name using loop

Is there a way without using arrays to write the following with a loop:

cout<<"This variable c1 ="c1
cout<<"This variable c2 ="c2
cout<<"This variable c3 ="c3

for(i=1,i<8,i++)
cout<<"This variable c%d =",i<<**????**<<

This is obviously not what I need to do, but it is the simplest example that I could think of with the same problem ... So what I would like to do is change the variables in a loop, not in the output!

EDIT: Thanks so much for all the input, here is a bit more code that will help illustrate my problem ... Im Using Cplex with C ++. The cycle does not end at seven, but when stopping criteria are met

static void  populatebyrow (IloModel model, IloNumVarArray x, IloRangeArray c)
{
    IloExpr c1(env);
    IloExpr c2(env);
    IloExpr c3(env);
    IloExpr c4(env);

    c.add(c1>=n);
    c.add(c2>=n); ...

    model.add(c);
}

, c, cplex. , Cplex, c (i) ... , , ... IloExprArray - , , , :

for(i= 0,...)
{
    c7 +=x[i];
}
+5
9

, . AFAIK ++.

+10

. .

int c[] = {2, 5, 7, 9, 3, 4, 6, 5};
for (int i = 0; i < 8; i++) cout // and so on...
+9
int* varArray[] = {&c1, &c2, &c3};
int size = sizeof( varArray) / sizeof(int*);

for( int i = 0; i < size; ++i)
{
   std::cout << "This variable c"<< i+1 << " = " << *varArray[i] << std::endl;
}
+6

- , . , , , , - :

#define Q(a) a
#define DO_THING(a, expr) do { Q(a)1 expr; Q(a)2 expr; Q(a)3 expr; Q(a)4 expr } while (0)

DO_THING(b, [i] = i);

:

do { b1  [i] = i; b2  [i] = i; b3  [i] = i; b4  [i] = i } while (0);

, , , . , -, , .

+1

, , . , - , , , , .

#include <iostream>
#include <conio.h>

#define N 10

using namespace std;

int main() {

    int * a = new int[N];

    for (int i = 0, * b = a; i < N; i++, b++) {
        *b = i;    
    }


    for (int i = 0, * b = a; i < N; i++, b++) {
        cout << *b << endl;
    }

    getch();
}

, - , . , , , . , , .

EDIT ( ), . , , ( , , ) HashMap. -, (), , (, ).

0

, " " , . -.

0

?

#include <iostream>
template<unsigned U>
struct Fac{ enum { value = U * Fac<U-1>::value};};
template<>
struct Fac<0>{ enum { value = 1};};
template<unsigned U>
struct Fib{ enum {value = (Fib<U-1>::value + Fib<U-2>::value)};};
template<>
struct Fib<0>{ enum {value = 0};};
template<>
struct Fib<1>{ enum {value = 1};};
template<unsigned U>
void show(){
    show<U-1>();
    std::cout << "Fib(" << U << ")=" << Fib<U>::value << "\t" << "Fac(" << U << ")=" << Fac<U>::value << std::endl;
}
template<>
void show<0>(){}

int main(int argc, char** argv){
    show<12>();
}

boost, .

0

, :

 IloNumVarArray x(env, 10);

 for(i=0; i<10; i++){
   x[i] = IloNumVar(env, 0, IloInfinity); 

   // Code for change the name of each variable
   char index[2]; 
   sprintf(index, "%d", i); 
   char variable_name[6] = "x"; 
   strcat(variable_name, index); 
   x[i].setName(variable_name);
 }
0

All Articles