在bool变量中存储整数值 [英] storing integer values in a bool variable
本文介绍了在bool变量中存储整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在一个布尔数组中存储整数值,但是当我打印出来的值,它们只出现为1和0,我假设表示true和false。有什么办法在bool中存储大于1或小于0的值吗?感谢提前的帮助! :D
I'm trying to store integer values in a boolean array, however when I print the values out, they only come out as 1's and 0's which I assume represent true and false. Is there any way to store values greater than 1 or less than 0 in a bool? Thanks in advance for the help! :D
这里是我想做的一个例子:
Here's a sample of what I'm trying to do:
#include <iostream>
#include <string>
using namespace std;
int main(){
bool set[2];
set[0] = 7;
set[1] = 13;
string setNotation = "{"+to_string(set[0])+", "+to_string(set[1])+"}";
cout << setNotation << endl; //prints out as {1, 1} instead of {7, 13}
//note: I have to use to_string to append and not cout << "{" << set[0] << ...
//because I'm using this in a method that returns a string
return 0;
}
推荐答案
只存储1或0。对不起。你可能想尝试一个int。
Nope, bools are designed to only store a 1 or a 0. Sorry about that. You might want to try an int.
这篇关于在bool变量中存储整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文