标签: c++
我想将汽车转移到sprintf格式,但如何!
char s[100]; int d = 4; sprintf(s, "%4s", "abc"); // i want the var 'd' replace '4', but how. cout << s;
答案 0 :(得分:4)
使用星号作为精度,并将所需表达式放在format参数之前:
sprintf(s, "%*s", d, "abc");