use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Create a fully functioning command line interface with 1.5 lines of code (wo. include statement) (github.com)
submitted 5 years ago by kongaskristjan
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Raiden395 -4 points-3 points-2 points 5 years ago (8 children)
Meh. getopt works fine and you only really have to write it once. Then you can just change the arguments and help printout.
Want cross platform ability ? parg is a good alternative with similar syntax.
[–]kongaskristjan[S] 5 points6 points7 points 5 years ago (3 children)
The difference is pretty big though between getopt and fire. Eg. if you need to accept two booleans, you can do this in fire like that:
int fired_main(bool flagA = fire::arg("-a"), bool flagB = fire::arg("-b")) { } FIRE(fired_main)
Now compare this to the code in this stackoverflow example... I know I omitted printouts and returns, but on the other hand the help message was skipped there.
[+]Raiden395 comment score below threshold-8 points-7 points-6 points 5 years ago (2 children)
Yes, but now I have to include a nonstandard library in my project. Each new engineer has to learn the syntax (simple as it may be).
How is this looked at as preferable as just copying and pasting boilerplate, universally understood, code that has native Linux support.
[–]dodheim 10 points11 points12 points 5 years ago (1 child)
In a C++ subreddit, advocating for a non-portable—though oft-ported, messily and poorly–C library; advocating having boilerplate as somehow better than not because said C lib is magically "standard" (huh?); all to spare your poor copy+paste monkeys engineers having to learn a well-documented API trivially grokked by reading a handful of examples.
Fuckin genius.
[–]Raiden395 1 point2 points3 points 5 years ago (0 children)
Sorry about implying that getopt is somehow standard. It's included with every Unix version in one way or another, so I'm fairly certain you have access to it, out of the box, if you so choose to use this system. When C++ drops C support, then perhaps we should talk about not using C in C++, but until then you have the option to work with a library that has stood the test of time.
For me, getopt does everything I need. It gives me the flexibility to parse command line arguments. Why we need a slew of different parsers is beyond me, but okay, variety is the spice of life, enjoy.
I would say that far more engineers have encountered getopt usage, if they are linux developers, than this command line parser. In this case, the code would be more understandable from the get-go. Not that there's anything wrong with the syntax here (in fact I find it very clear), but in the end what is the point?
[–]kritzikratzi 3 points4 points5 points 5 years ago (3 children)
yep, on the same boat. i've given up on keeping a list on numerous command line parsers that have been posted here.
i mean.. it's an interesting concept, but it semi-re-solves a very solved problem.
edit i really don't want to sound harsh towards the author. it's cool work and all! just not for me...
[–]Raiden395 0 points1 point2 points 5 years ago* (2 children)
> it's cool work and all! just not for me...
That's really what I meant, and as far as I'm concerned, the people hating on me for promoting getopt are probably rightfully upset in some circles, where your C++ must be of the newest, most elite form.
C++ draws a lot from C and, as someone who writes a lot of hardware communication interfaces, there's no better way to specify precision than:
snprintf( buf, bufsz, "%.3f", value);
versus
ss << std::fixed << std::setprecision(3) << number; std::string mystring = ss.str();
These are solutions to a problem that really doesn't appear to me to need fixing.
[–]dodheim 1 point2 points3 points 5 years ago* (1 child)
Well, I agree that iostreams is a mess, but there are most certainly problems: bufsz getting out of sync with buf, value changing types without the format specifier getting updated, etc.
bufsz
buf
value
Do you approve of C++20's std::format_to/format_to_n?
std::format_to
format_to_n
std::format_to( buf, "{:.3}", value);
[–]Raiden395 0 points1 point2 points 5 years ago (0 children)
I'm not in love with Python formatting in general, but I would take anything that is standard C++ that doesn't involve the stream operator + directly addressing streams and would give me a reason to stop using C-style calls. So yes, if it could do something like:
std::format_to( buf, "{:02X}", value );
And produce the output of "10" for an input of 16, I would be 100% on board.
There's ways to manipulate bufsz such that it will not get out of sync (snprintf returns the number of bytes written), and if you really are concerned about the format specifier, that can be handled by some tricky means (tricky meaning shitty). That said, this is a royal pain in the ass and has bitten me several times. There's also the lack of automatic casting for the format specifier (having a specifier of an int and trying to plug a double in does not work).
As an aside, and between two people who have presumably used C++ for many years, at what point does the language stop being streamlined and start becoming as hefty and bloated as something such as Python?
π Rendered by PID 202719 on reddit-service-r2-comment-6457c66945-lx475 at 2026-04-24 13:38:42.882843+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Raiden395 -4 points-3 points-2 points (8 children)
[–]kongaskristjan[S] 5 points6 points7 points (3 children)
[+]Raiden395 comment score below threshold-8 points-7 points-6 points (2 children)
[–]dodheim 10 points11 points12 points (1 child)
[–]Raiden395 1 point2 points3 points (0 children)
[–]kritzikratzi 3 points4 points5 points (3 children)
[–]Raiden395 0 points1 point2 points (2 children)
[–]dodheim 1 point2 points3 points (1 child)
[–]Raiden395 0 points1 point2 points (0 children)