C++ Logo

std-proposals

Advanced search

Re: std::string to_string(bool value);

From: Garrett May <garrett.ls.may_at_[hidden]>
Date: Sat, 20 Jul 2019 21:21:04 +0100
std::boolalpha is already available:

int main(){
    bool const a = true;
    std::cout << std::boolalpha << a << std::endl;
}

My gut instinct here is that one is supposed to control how one wants data
to be printed out, in the same way as how float/double precision is done.


On Sat, 20 Jul 2019, 21:16 Jonny Grant via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> Hello
>
> Could std::string to_string(bool value); be added? Currently it outputs
> as a number due to the implicit conversion to int?
> Feel it would have been more appropriate as "true" or "false".
>
> http://www.cplusplus.com/reference/string/to_string/
>
> $ g++-8 -Wall -o to_string to_string.cpp
> $ ./to_string
> 1
>
>
>
> // g++-8 -Wall -o to_string to_string.cpp
> #include <string>
> #include <iostream>
> int main()
> {
> const bool a = true;
> const std::string b(std::to_string(a));
> std::cout << b << std::endl;
> }
>
> Cheers, Jonny
>
>
>
> .
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2019-07-20 15:23:12