在二进制串的数字之间给出空间
答
当你与++的字符串存储在列C上工作,使用索引可以访问或使用迭代器
string str = "mystring";
// Declaring iterator
std::string::iterator it;
// Declaring reverse iterator
std::string::reverse_iterator it1;
// Displaying string
cout << "The string using forward iterators is : ";
for (it=str.begin(); it!=str.end(); it++)
cout << *it;
cout << endl;
// Displaying reverse string
cout << "The reverse string using reverse iterators is : ";
for (it1=str.rbegin(); it1!=str.rend(); it1++)
cout << *it1;
答
您可以随时去的简单方法,分配一个新的字符串(几乎)是输入字符串大小的两倍,并且一次填充一个字符。
例如:
std::string expand(const std::string& str)
{
std::string new_str;
size_t size = str.size();
new_str.resize(size*2-1);
for (size_t n = 0; n < size-1; n++)
{
new_str[n*2+0] = str[n];
new_str[n*2+1] = ' ';
}
new_str[size*2-2] = str[size-1];
return new_str;
}
的可能的复制[?我如何把一个空间,在这个输出每四个字符之间(https://*.com/questions/26302820/how-do- I-放-A-空间在其间-每四字符功能于该输出) –