Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
345 views
Welcome To Ask or Share your Answers For Others

1 Answer

Nope, bools are designed to only store a 1 or a 0. Sorry about that. You might want to try an int.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...