im new in c++ and i am creating a version of cat for practicing what i have learned so far. What im doing for managing the command line arguments is converting them to library strings and then using them, but now i have the doubt if it is the correct / most optimal way to do it

  • equidamoid@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    1 year ago

    Use std::string_view to sort of get the safety of std::string without copying the contents (just in general make sure the original c string won’t get freed or overwritten, which won’t happen to argv in your case).

    Or just std::string and yolo, the overhead of copying the contents is negligible in your use case.

    • rmam@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      std::string_view

      Small caveat: std::string_view was introduced in C++17. Not all projects made that jump yet.

      • SuperFola@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        If they are just practicing it isn’t a problem, C++17 is already 6 years old and the open source community should get onboard imo

        • rmam@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          1 year ago

          Last time I checked, over half of the C++ community was still using C++14 or older.

          Jumping into the latest and greatest is only trivial in small pet projects. In professional settings this requires significant amounts of work.