3 ms·
but it removes three classes of errors entirely when compared to printf / scanf: - wrong arguments types (mostly solved by libraries such as fmt tho): printf("
by jcelerier 6y ago
but it removes three classes of errors entirely when compared to printf / scanf:
- wrong arguments types (mostly solved by libraries such as fmt tho): printf("%d", 0.5);
- too much / not enough arguments passed: printf("%d", 0, 1);
- passing unsanitized strings as template argument: printf(some_string_i_got_from_the_network_lol, arg_1, arg_2);
the << method makes these three errors impossible.
Also << does not allow you to have something like printf's %n, which writes to one of its arguments.
fmt is able to give compile-time validation of string literals, but at a hefty compile-time cost. In my opinion the best solution would be string interpolation, but we're definitely not there yet...
- account42 6y ago> - wrong arguments types (mostly solved by libraries such as fmt tho): printf("%d", 0.5); > - too much / not enough arguments passed: printf("%d", 0, 1); -Wformat > - passing unsanitized strings as template argument: printf(some_string_i_got_from_the_network_lol, arg_1, arg_2); -Wformat-nonliteral