c ++ sprintf格式如何转移汽车

时间:2012-11-19 02:38:41

标签: c++

我想将汽车转移到sprintf格式,但如何!

char s[100];
int d = 4;
sprintf(s, "%4s", "abc"); // i want the var 'd' replace '4', but how.
cout << s;

1 个答案:

答案 0 :(得分:4)

使用星号作为精度,并将所需表达式放在format参数之前:

sprintf(s, "%*s", d, "abc");