Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Degree Celsius in a string in C++ [closed]

Tags:

c++

console

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 "°".

like image 782
Mike Portnoy Avatar asked Dec 01 '22 16:12

Mike Portnoy


2 Answers

Try:

std::cout << "Temperature: " << sValue << "\370";
like image 176
Daniel Avatar answered Dec 26 '22 11:12

Daniel


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;
like image 28
tuskcode Avatar answered Dec 26 '22 12:12

tuskcode