Date: Sat, 20 Jul 2019 21:39:40 +0100
Hi Garrett
Many thanks for your reply.
Yes, I see std::boolalpha sets an I/O flag.. but seems a bit of a long
way to get it into a string, I'd need to use in conjunction with
std::istringstream to get a string...
I wanted to do something like this example:
*Idea*
std::string fmt(const std::string header, bool b)
{
return header + " " + std::to_string(b) + " set";
}
*How I would do now*
As his doesn't work, I'd have it at present as:
std::string fmt(const std::string header, bool b)
{
return header + " " + b?"true":"false" + " set";
}
Regards, Jonny
On 20/07/2019 21:21, Garrett May via Std-Proposals wrote:
> 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]
> <mailto: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] <mailto:Std-Proposals_at_[hidden]>
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
Many thanks for your reply.
Yes, I see std::boolalpha sets an I/O flag.. but seems a bit of a long
way to get it into a string, I'd need to use in conjunction with
std::istringstream to get a string...
I wanted to do something like this example:
*Idea*
std::string fmt(const std::string header, bool b)
{
return header + " " + std::to_string(b) + " set";
}
*How I would do now*
As his doesn't work, I'd have it at present as:
std::string fmt(const std::string header, bool b)
{
return header + " " + b?"true":"false" + " set";
}
Regards, Jonny
On 20/07/2019 21:21, Garrett May via Std-Proposals wrote:
> 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]
> <mailto: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] <mailto:Std-Proposals_at_[hidden]>
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
Received on 2019-07-20 15:41:39