• @SpaceNoodle@lemmy.world
    link
    fedilink
    0
    edit-2
    1 month ago

    If I’m writing C++, I’m usually optimizing for portability over performance, in which case I would prefer std::endl as it would yield the best results regardless of platform; it also keeps the end-of-line character out of other strings, making code just a little cleaner.

    \n is for when I’m done pretending that anything that isn’t Unix-like is OK, or I’m counting the cycles of every branch instruction.

    • Oriel Jutty :hhHHHAAAH:
      link
      fedilink
      01 month ago

      std::endl provides zero portability benefits. C++ does have a portable newline abstraction, but it is called \n, not endl.

        • Oriel Jutty :hhHHHAAAH:
          link
          fedilink
          01 month ago

          The same is true of std::endl. std::endl is simply defined as << '\n' << std::flush; nothing more, nothing less. In all cases where endl gives you a “properly translated” newline, so does \n.

          • @zenforyen@feddit.org
            link
            fedilink
            01 month ago

            Yeah it’s an artificial dichotomy based on a popular misconception of what std::endl is and how \n is interpreted.

            Ultimately it does not ask about line endings, but about flushing, which is a completely orthogonal question.

            • AnyOldName3
              link
              fedilink
              01 month ago

              It’s controlled by whether the stream’s opened in text mode or binary mode. On Unix, they’re the same, but on Windows, text mode has line ending conversion.