cout对于bool是真的(true) [英] cout true for bool(true)

查看:185
本文介绍了cout对于bool是真的(true)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我怎么能


bool a(true);

cout<< a;


并期望打印出来


true


而不仅仅是


1

感谢

解决方案

Gary Wessle写道:
< blockquote class =post_quotes>
我怎么能


bool a(true);

cout<< a;


并期望打印出来


true


而不仅仅是


1



在有人提供更便宜的答案之前,我可以问一个人是否会灌输一个

locale?


(请注意,有些文化不能称为正布尔值true;-)


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!


Gary Wessle写道:




我怎么能


bool a(true);

cout<< a;


并期望打印出来


true


而不仅仅是


1



这样的东西?

bool a = true;

std :: cout.setf(std :: ios :: boolalpha);

std :: cout<< a<< " \ n";


问候,

Sumit。


Gary Wessle写道:




我怎么能


bool a(true);

cout<< a;


并期望打印出来


true


而不仅仅是


1



将操纵者''boolapha''输出到''cout''流

输出你的布尔值之前。还要确保你

#include< iomanip> ;.


HTH,

- J.


Hi
how can I

bool a(true);
cout << a;

and expect it to print out

true

and not just

1
thanks

解决方案

Gary Wessle wrote:

how can I

bool a(true);
cout << a;

and expect it to print out

true

and not just

1

Before someone provides a cheaper answer, may I ask if one might imbue a
locale?

(Note that some cultures don''t call a positive boolean "true" ;-)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


Gary Wessle wrote:

Hi
how can I

bool a(true);
cout << a;

and expect it to print out

true

and not just

1


Something like this?
bool a = true;
std::cout.setf(std::ios::boolalpha);
std::cout << a << "\n";

Regards,
Sumit.


Gary Wessle wrote:

Hi
how can I

bool a(true);
cout << a;

and expect it to print out

true

and not just

1

Output the manipulator ''boolapha'' to the ''cout'' stream
before outputting your booleans. Also make sure you
#include <iomanip>.

HTH,
- J.


这篇关于cout对于bool是真的(true)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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