Date: Sun, 2 Oct 2022 10:56:00 +0200
Hi Olaf,
maybe std::format_to_n is what you require?
Cheers,
Kilian
On 02.10.22 10:35, Olaf van der Spek via Std-Discussion wrote:
> Hi,
>
> This snippet overflows the destination buffer. Is format_to too easy to misuse?
> Shouldn't it requires an iterator to the end so it could avoid this issue?
> It seems like a modern equivalent of fgets()
>
> #include <format>
> #include <iostream>
>
> int main()
> {
> char d[10] = {};
> std::format_to(d, "0123456789 {}", 42);
> std::cout << std::string_view(d, 10) << std::endl;
> }
maybe std::format_to_n is what you require?
Cheers,
Kilian
On 02.10.22 10:35, Olaf van der Spek via Std-Discussion wrote:
> Hi,
>
> This snippet overflows the destination buffer. Is format_to too easy to misuse?
> Shouldn't it requires an iterator to the end so it could avoid this issue?
> It seems like a modern equivalent of fgets()
>
> #include <format>
> #include <iostream>
>
> int main()
> {
> char d[10] = {};
> std::format_to(d, "0123456789 {}", 42);
> std::cout << std::string_view(d, 10) << std::endl;
> }
Received on 2022-10-02 08:56:05