Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对齐文本并更改空格数_C++_C - Fatal编程技术网

C++ 对齐文本并更改空格数

C++ 对齐文本并更改空格数,c++,c,C++,C,我试图格式化我的字符串,因为我有两个字符串,一个包含:“1”和 第二个包含:“test”并希望输出整个字符串,其中空格为: 1个测试 我是这样说的: printf("%-10s %s", "1", "test"); 但是如何在不更改格式的情况下更改空格“%-10s” int amount_of_space = 10; like: printf("%-*s %s", "1", "test", amount_of_space) 我该怎么做???在C或C++中,请帮助我出 < P>代码> Pr

我试图格式化我的字符串,因为我有两个字符串,一个包含:“1”和

第二个包含:“test”并希望输出整个字符串,其中空格为:

1个测试

我是这样说的:

printf("%-10s %s", "1", "test");
但是如何在不更改格式的情况下更改空格“%-10s”

int amount_of_space = 10;

like: printf("%-*s %s", "1", "test", amount_of_space) 
我该怎么做???在C或C++中,请帮助我出

< P>代码> PrimTf(“%-*%s”),“空间”的“金额”,“1”,“测试”);代码>
printf(“%-*s%s”,空间量,“1”,“test”)

*在格式字符串中位于第一位-因此参数
amount\u of_space
必须位于逗号之后

i、 在格式字符串中,顺序是*,s&s-因此在逗号之后,您需要填充*,第一个字符串,然后是第二个字符串

*在格式字符串中位于第一位-因此参数
amount\u of_space
必须位于逗号之后

i、 在格式字符串中,顺序是*,s&s-因此在逗号之后,您需要填写*,第一个字符串,然后是第二个字符串。

使用以下方法:
printf(“%-*s%s”,空间量,“1”,“test”)

使用以下命令:
printf(“%-*s%s”,空间量,“1”,“test”) 

,C++中的

cout << left << setw(amount_of_spaces) << "1" << "test";

<代码> CUT

,C++中的是:

cout << left << setw(amount_of_spaces) << "1" << "test";

我可以在6分钟内选择接受你的答案吗,因为你是唯一一个向我解释事情的人:)我将在6分钟内选择接受你的答案,因为你是唯一一个向我解释事情的人:)