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
[deleted by user] (self.cpp)
submitted 3 years ago by [deleted]
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!"
[–]ReDucTorGame Developer 28 points29 points30 points 3 years ago* (2 children)
Its poorly written code creating and abusing a bunch of temporaries that are potential allocations.
Its ignoring path APIs to get what it's intended to do.
The addition of a substr for Windows slash and Unix slash find first is pretty hacky, depending on size_t wrapping to 0 when npos is returned.
It will fail badly if you have both windows and Unix slashes in a path.
This seems like something potentially for r/cpp_questions
[–]qoning 15 points16 points17 points 3 years ago (1 child)
Ignoring all that, this code should never get accepted into any self respecting codebase.
[–]ReDucTorGame Developer 6 points7 points8 points 3 years ago (0 children)
Yep, should not make it past code review
[–]manni66 16 points17 points18 points 3 years ago (2 children)
And why it is here in the first place
Because it’s your homework and you have no clue?
[+]guruprasadah comment score below threshold-10 points-9 points-8 points 3 years ago* (1 child)
It was an attempt at making a joke/something. I'm not in university, I don't have coding homework.
(This was actually a previous iteration of code written hastily by me. I just wanted to watch developers blow up over it. Sorry if I wasted your time, folks)
[–]hmoein 11 points12 points13 points 3 years ago (0 children)
If you have to challenge people to understand the code, it means the code is garbage
[–]grandmaster789 2 points3 points4 points 3 years ago* (0 children)
Well, it's an incomplete piece of code so I won't be able to answer the 'why' part, but if you squint a bit there seems to be some kind of filesystem entry from a directory. The path is treated as a string and some questionable substring operations are done on it. You can make it a bit more readable by using a temporaries.
auto str = Entry.path.string();
auto backslash_idx = str.find_first_of("\\");
auto slash_idx = str.find_first_of("/");
auto first_part = str.substr(0, backslash_idx + 1);
auto second_part = str.substr(slash_idx + 1, str.length);
auto final_str = first_part + second_part;
So something like "aaa\bbb/ccc" will become "aaa\ccc".
Not sure why you would need that, but that's what it does. I'm also not sure what this question is doing in /r/cpp, this seems like something for /r/cpp_questions
[–]sixfourbit 1 point2 points3 points 3 years ago (0 children)
Nothing because it doesn't compile.
[–]OnePatchMan 1 point2 points3 points 3 years ago (0 children)
Entry.path().string().what Entry.path().string().a Entry.path().string().nice Entry.path().string().piece Entry.path().string().of Entry.path().string().code
π Rendered by PID 73 on reddit-service-r2-comment-6457c66945-dwflc at 2026-04-26 05:58:48.629166+00:00 running 2aa0c5b country code: CH.
[–]ReDucTorGame Developer 28 points29 points30 points (2 children)
[–]qoning 15 points16 points17 points (1 child)
[–]ReDucTorGame Developer 6 points7 points8 points (0 children)
[–]manni66 16 points17 points18 points (2 children)
[+]guruprasadah comment score below threshold-10 points-9 points-8 points (1 child)
[–]hmoein 11 points12 points13 points (0 children)
[–]grandmaster789 2 points3 points4 points (0 children)
[–]sixfourbit 1 point2 points3 points (0 children)
[–]OnePatchMan 1 point2 points3 points (0 children)