如何在 C++ 中的字符串中显示摄氏度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23777226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display Degree Celsius in a string in C++
提问by Mike Portnoy
I need to display a string with values like 36 Deg Celsius.
我需要显示一个字符串,其值为 36 摄氏度。
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".
我无法弄清楚如何显示度数(o 符号)而不是写“摄氏度”。
回答by Daniel
Try:
尝试:
std::cout << "Temperature: " << sValue << "0";
回答by tuskcode
You might find the following link helpful for the full ascii table.
您可能会发现以下链接对完整的 ascii 表很有帮助。
Here is a solution I found here on SO: Including decimal equivalent of a char in a character array
这是我在 SO 上找到的解决方案:包括字符数组中字符的十进制等效值
But to summarize, this would do fine
但总而言之,这会很好
char * val = "37";
string temp(val);
temp.append("\xB0");
cout << temp;
回答by Mike Portnoy
Just in-case if anyone wants to try this:
以防万一有人想试试这个:
sFinish.append("\u2103");
this will display Deg celsius :)
这将显示摄氏度 :)