布尔转换在C ++文本 [英] Converting bool to text in C++

查看:119
本文介绍了布尔转换在C ++文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个愚蠢的问题,但有什么办法一个布尔值转换为字符串,这样1变为真正的0变为假?我可以只使用if语句,但如果有一种方法可以做到这将是很好的知道用语言或标准库。另外,我是一个学究。 :)

Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to "true" and 0 turns to "false"? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I'm a pedant. :)

推荐答案

如何使用C ++语言本身?

How about using the C++ language itself?

bool t = true;
bool f = false;
std::cout << std::noboolalpha << t << " == " << std::boolalpha << t << std::endl;        
std::cout << std::noboolalpha << f << " == " << std::boolalpha << f << std::endl;

这篇关于布尔转换在C ++文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆