Is there a C macro to generate repeat string?(是否有 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;
}
这篇关于是否有 C 宏来生成重复字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!