Returning a number of periods using to_string

I am asking the user for a number and want to return that many periods in a row to the user using to_string. Here is my code:

string dots(int a)
{
for(int i=0; i < a; ++i)
{
return to_string('.');
}
}

For some reason the output is 46. Please advise. Thank you!
ascii 46 is period
https://ascii.cl/

How do I make it so that it will return just the period '.' using to_string?
1
2
3
4
string dots( int a )
{
   return string( a, '.' );
}
Last edited on
It seems that you did not pay attention to what jlb wrote in http://www.cplusplus.com/forum/beginner/233290/#msg1048853


The std::to_string converts numerical value to string.
That is in its description: http://www.cplusplus.com/reference/string/to_string/

The '.', is not a numerical value, is it?


The std::string has multiple constructors. One of them takes a number and a char. http://www.cplusplus.com/reference/string/string/string/
Topic archived. No new replies allowed.