spaces insetred into string

I have my code below where an int less than 32767 has to be inputted then printed, then printed in reverse and then the original printed with spaces...
I have managed to reverse it, but struggling with the spaces bit. I have the length of the integer so was thinking of using a for loop or the like, Also I have been looking at http://www.cplusplus.com/reference/string/string/insert/
Any help is greatly appreciated!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include<iostream>
#include<string>
#include<sstream>

using namespace std;

int quoitent (int, int );
int remainder ( int , int );

int main()
	{
		int number;
		cout << "input an int <= 32767: ";
		cin >> number;
			while ( number > 32767 || !cin )
				{
					cin.clear();
					cin.ignore();
					cout << "input an int <= 32767: ";
					cin >> number;
				}
				
		cout << number << " as int" << endl;
				
				
			string result;
			ostringstream convert;
			convert << number;
			result = convert.str();
			
			cout << result << " as string" << endl;
			
			string backwards;
			
			cout << "lenght of string is: " << result.size() << endl;
		
			backwards = string ( result.rbegin(), result.rend() );
			
			cout << backwards << endl;	
		return 0;
		
	}
I mean, this simple for-loop would do

1
2
3
4
5
for(int i = 0; i < result.size(); i++)
{
	cout << result[i] << " ";
			    
}
lol cheers! sorry it has been a very long day. You know when you get a mental block and can't think...

Thanks for your help - trivial as it was! A good night's sleep is needed!!!

James
Topic archived. No new replies allowed.