6

I need to display a string with values like 36 Deg Celsius.

string sFinish = NULL;
string sValue = "36"; 
sFinish.append(sValue);
sFinish.append(" Deg Celsuis");
cout<<"Degree = "<<sFinish;

I am not able to figure out how to display degree (o symbol) instead of writing "Deg Celsius".

If you just copy paste "°" string into code - it shows extra character - like this "°".

TarmoPikaro
  • 4,723
  • 2
  • 50
  • 62
Mike Portnoy
  • 175
  • 1
  • 1
  • 11

3 Answers3

13

Try:

std::cout << "Temperature: " << sValue << "\370";
Daniel
  • 544
  • 1
  • 10
  • 21
5

You might find the following link helpful for the full ascii table.

Here is a solution I found here on SO: Including decimal equivalent of a char in a character array

But to summarize, this would do fine

char * val = "37";
string temp(val);
temp.append("\xB0");    
cout << temp;
Community
  • 1
  • 1
tuskcode
  • 317
  • 2
  • 14
2

Just in-case if anyone wants to try this:

sFinish.append("\u2103");

this will display Deg celsius :)

Mike Portnoy
  • 175
  • 1
  • 1
  • 11