Hi friends,

I would like to insert "whitespace" between the numbers of my string str3 and after concatenate with str1 and str2, as str1 << str2 << str3. This is an example:

E.g.: 200 3 1 2 3 4 5 6 7 8 9

Could you help me? I had problems with "insert". After I need to concatenate like the example and write a file.

Cheers,

Sads

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

int main()
{
      string str1 = "200";
	  string str2 = "3";
	  string str3 = "123456789";

	
	  for(int i=0;i<str3.length();i++)
	  {
		  str3.insert(str3.end(),' ');
	  }


	
}

Recommended Answers

All 2 Replies

str1 = "$#!%";
str1 += ' ';
str1 += " the ";
str1 += ' ';
str1 += " police.";

Thanks Clinton!

str1 = "$#!%";
str1 += ' ';
str1 += " the ";
str1 += ' ';
str1 += " police.";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.