C语言字符串与变量名的转换

#include 
#include 
#include 
#include 
#include

using namespace std;

#define to_str(name)  (#name)

#define TIMx_ARR(n) TIM##n##_ARR

int main(void)
{
    freopen("G:\\data.txt", "r", stdin);

    int TIM1_ARR = 0;
    int TIM2_ARR = 0;


    TIMx_ARR(1) = 1;
    TIMx_ARR(2) = 2;

    cout << TIM1_ARR << endl;
    cout << TIM2_ARR << endl;
    cout << TIMx_ARR(2) << endl;

    for(int i = 1; i <= 2; i++)
    {
   //     TIMx_ARR(to_str(i)) = i*4;       error , to_str(i) can not replace before TIMx_ARR;
    }

    printf("%s", to_str(457779));

    return 0;
}

你可能感兴趣的:(C语言基本算法)