this post was submitted on 25 Jul 2023
2 points (100.0% liked)

C++

1732 readers
22 users here now

The center for all discussion and news regarding C++.

Rules

founded 2 years ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[–] equidamoid 4 points 2 years ago* (last edited 2 years ago) (2 children)

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.

[–] prettydarknwild 1 points 2 years ago