문제

Let the first row be:

#define TAG_LEN 32

Now, I need to concatenate it with a literal string constant; something like that:

puts("Blah" [insert your answer] TAG_LEN); // I need "Blah32".
도움이 되었습니까?

해결책

#define STR_NOEXPAND(tokens) # tokens
#define STR(tokens) STR_NOEXPAND(tokens)
puts("Blah" STR(TAG_LEN));

다른 팁

you can do:

printf("Blah%d", TAG_LEN);

or if you have a string

char *yourString;// initiate it with your value

printf("Blah%s%d",yourString, TAG_LEN);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top