converting a vector of characters to a string

closed account (oG8U7k9E)
I wrote this function to take a integer and convert it into a string that represents a Roman numeral. I am having trouble converting creating the string. This is the function and it works, but I would prefer my string to be the correct size any advice?

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
43
void get_roman_help(int& remainder, int&temp,int div,vector<char>& r_str, char c1, char c2){

	temp =int(remainder/div);
	remainder = remainder%div;
	if(temp>4)temp=4;
	switch(temp){
		case 1:
			r_str.push_back(c1);
			break;
		case 2:
			r_str.push_back(c1);
			r_str.push_back(c1);
			break;
		case 3:
			r_str.push_back(c1);
			r_str.push_back(c1);
			r_str.push_back(c1);
			break;	
		case 4:
			r_str.push_back(c1);
			r_str.push_back(c2);
			break;
	}
}
string Roman::get_roman(){
	vector<char>r_str;
	int remainder = value;
	int temp =value;
	get_roman_help(remainder,temp,1000,r_str,'M','.');
	get_roman_help(remainder,temp,500,r_str,'D','M');
	get_roman_help(remainder,temp,100,r_str,'C','D');
	get_roman_help(remainder,temp,50,r_str,'L','C');
	get_roman_help(remainder,temp,10,r_str,'X','L');
	get_roman_help(remainder,temp,5,r_str,'V','X');
	get_roman_help(remainder,temp,1,r_str,'I','V');

	//debugging test
	string returnValue="                   ";
	for(int i =0;i<r_str.size();++i){
		returnValue[i]=r_str[i];
	}
	return returnValue;
}
string returnValue;
and
returnValue += r_str[i];

or, better yet,

return string( r_str.begin(), r_str.end() );
closed account (oG8U7k9E)
Thank you jsmith.
Topic archived. No new replies allowed.