• jecxjo
    link
    fedilink
    English
    232 months ago

    They aren’t the same thing so the comparison is weird.

    endl has a flush which is important when doing something like embedded work or RTOS development. If i was doing multiple lines they all were \n until the last line when i actually want to push the buffer.

    Obviously depending on the tuning of the compiler’s optimization multiple flushes could be reduced but the goal should always be to write as optimal as possible.

    • MrScottyTay
      link
      fedilink
      English
      22 months ago

      It might do. I encountered it last week as I needed it for a powershell script. So it exists in that at least

    • grandel
      link
      fedilink
      English
      22 months ago

      I like that you added the absolute namespace identifier or whatever its called

  • Digital Mark
    link
    fedilink
    English
    52 months ago

    If you write to a text (as opposed to binary) stream, \n produces \n or \r\n (or \r if old enough) depending on platform just fine.

    Nobody should be using C++ anyway, but plenty of languages have silly system newline constants, which do nothing useful.

      • @[email protected]
        link
        fedilink
        English
        42 months ago

        It’s memory unsafe and it’s syntax is indistinguishable from the runes which summon cthulu.

        • @[email protected]
          cake
          link
          fedilink
          12 months ago

          Memory unsafe C++ is a choice. With modern C++ you have no excuse for accessing raw pointers or arrays without range checking if memory safety is a priority.

            • @[email protected]
              cake
              link
              fedilink
              12 months ago

              As I said: There are tools in place in modern C++ that are designed to catch the errors you make. If you are using a raw pointer when you could have used a reference, or accessing an array without range checking, those are choices you’ve made. They may be valid choices in your use-case, but don’t go complaining that the language is “unsafe” when it gives you the option to code with guard rails and you choose to forgo them.

              • @[email protected]
                link
                fedilink
                12 months ago

                I’m a full time C++ developer, mostly doing high performance data processing and some visualization and TUI tools, and as someone loving C++, it’s not as simple as you frame it. In sufficiently complex code you still have to deal with these problems. Rust has some good mechanisms in place to avoid these and there are things on the way for c++26 though.

                • @[email protected]
                  cake
                  link
                  fedilink
                  12 months ago

                  I don’t mean to say that C++ is in any way without faults. If performance is crucial, that can definitely be a reason to forgo some of the guard-rails, and then you’re on your own.

                  I guess my issue with the “C++ is unsafe”-trope, is that it usually (in my experience) comes from people not having heard of all the guard-rails in the first place, or refusing to use them when appropriate. They write C++ as if they were writing C, and then complain that the language is unsafe when they’ve made a mistake that is easily avoided using stl-containers.

        • MrScottyTay
          link
          fedilink
          English
          1
          edit-2
          2 months ago

          I think the memory stuff is pretty good nowadays. I’m sure I saw modern C++ can have a garbage collector. And the syntax is only runelike until you learn it, like any language really. As an industry C# developer I’ve recently taken up C++ as a hobby to better learn the workings of low level code and I’ve been enjoying it so far.

          • @[email protected]
            link
            fedilink
            English
            1
            edit-2
            2 months ago

            c# has lovely syntax and languages like it and python are pretty readable with basic coding knowledge. C++ if you don’t know a symbol there’s too many options and the risk of misunderstanding is too high.

            I will agree with your claim “if you learn the syntax then you know the syntax” but I don’t find this valuable.