Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Visual c++ 循环以继续在字符串中添加空格?_Visual C++_Command Line Interface - Fatal编程技术网

Visual c++ 循环以继续在字符串中添加空格?

Visual c++ 循环以继续在字符串中添加空格?,visual-c++,command-line-interface,Visual C++,Command Line Interface,我有以下代码: sHexPic = string_to_hex(sPic); sHexPic.insert(sHexPic.begin() + 2,' '); sHexPic.insert(2," "); 我想知道我如何能把它放入一个计数循环,并在每2个字符后添加一个空格。到目前为止,所有这些都是将字符串“35498700”转换为“35498700”,最后我希望最终结果类似于“35498700” 我假设您必须获得字符串的长度和其中的字符数 我正试图用c++/cli实现这一点 谢

我有以下代码:

sHexPic = string_to_hex(sPic);
    sHexPic.insert(sHexPic.begin() + 2,' ');
    sHexPic.insert(2," ");
我想知道我如何能把它放入一个计数循环,并在每2个字符后添加一个空格。到目前为止,所有这些都是将字符串“35498700”转换为“35498700”,最后我希望最终结果类似于“35498700”

我假设您必须获得字符串的长度和其中的字符数

我正试图用c++/cli实现这一点


谢谢。

< P>这里,如何在C++中使用字符串:(我使用C库,因为我对C更熟悉)

#包括
#包括
使用名称空间std;
int main()
(
字符串X;
int i;
int-y;
X=35498700;
y=X.size();

对于(i=2;i这里是如何在C++中使用字符串:)(我使用C库,因为我对C更熟悉)

#包括
#包括
使用名称空间std;
int main()
(
字符串X;
int i;
int-y;
X=35498700;
y=X.size();
对于(i=2;无问题伴侣:)任何时候!:)无问题伴侣:)任何时候!:)可能的重复可能的重复
#include <stdio.h>
#include <string>

using namespace std;

int main()
(
   string X;
   int i;
   int y;

   X = 35498700;
   y= X.size();

   for(i=2;i<y;i+=2)
   {
      X.insert(i," ");
      y=x.size(); //To update size of x
      i++; //To skip the inserted space
   }

   printf("%s",X);

   return 0;
}