Skip Navigation
58 comments
  • printf is superior and more concise, and snprintf is practically the only C string manipulation function that is not painful to use.

    Try to print a 32-bit unsigned int as hexadecimal number of exactly 8 digits, using cout. You can do std::hex and std::setw(8) and std::setfill('0') and don't forget to use std::dec afterwards, or you can just, you know, printf("%08x") like a sane person.

    Just don't forget to use -Werror=format but that is the default option on many compilers today.

    C++23 now includes std::print which is exactly like printf but better, so the whole argument is over.

    • I went digging in cppref at the format library bc I thought c++20 or c++23 added something cool.

      Found std::print and was about to reply to this comment to share it bc I thought it was interesting. Then I read the last sentence.

      Darn you and your predicting my every move /j

  • Wasn't this {fmt} library merged into STL now? Does this solve this issue?

    Anyways, there was also a constant that is the OS line ending without a flush, right?

  • \n is fun until you’re an a system that needs an additional \r

    • Unix needed only \n because it had complex drivers that could replace \n with whatever sequence of special characters the printer needed. Also, while carriage return is useful, they saw little use for line feed

      On dos (which was intended for less powerful hardware than unix) you had to actually use the correct sequence which often but not always was \r\n (because teleprinters used that and because it's the "most correct" one).

      Now that teleprinters don't exist, and complex drivers are not an issue for windows, and everyone prefers to have a single \n, windows still uses \r\n, for backward compatibility.

    • Bedeviled NXP/ARM SDK stdlib. Hate it, we need \n\r there. Why????!?!?! What a PITA.

58 comments