是否有 C 宏来生成重复字符串?
假设我要生成------
,只有-
,有没有C宏可以生成重复的字符串?
Suppose I want to generate ------
, with only -
, is there a C macro to generate repeated string ?
推荐答案
使用boost,例如
#include <stdio.h>
#include <boost/preprocessor/repetition/repeat.hpp>
#define Fold(z, n, text) text
#define STRREP(str, n) BOOST_PP_REPEAT(n, Fold, str)
int main(){
printf("%s
", STRREP("-", 6));
return 0;
}
相关文章