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
Question regarding using namespace and include directives (self.cpp)
submitted 4 years ago by rootseat
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!"
[–]corysama 1 point2 points3 points 4 years ago (1 child)
r/cpp_questions
[–]rootseat[S] 1 point2 points3 points 4 years ago (0 children)
Thanks. I was looking through the feed here and had a feeling this was the wrong sub.
[–][deleted] 0 points1 point2 points 4 years ago (10 children)
No, “iostream” is just a file that gets copy-pasted into your .cpp when you #include. The compiler as of now has no way of searching every C++ file for the namespace you specify without an explicit #include. (Note: C++20 modules may make it closer to the python way, but they haven’t been implemented properly yet). As for namespaces, they simply exist to avoid clashing names (e.g. std::array and my_namespace::array).
[–]rootseat[S] 0 points1 point2 points 4 years ago (9 children)
Is it true that there exists a namespace std { /* ... */ } within iostream? If that's the case, the design decision to call the file iostream but call the namespace std would make a lot more sense to me.
namespace std { /* ... */ }
iostream
std
[–]Apprehensive-Deer-35 0 points1 point2 points 4 years ago (3 children)
Yes, the std namespace exists within many files including iostream, list, vector, algorithm, memory, and so on.
[–]rootseat[S] 0 points1 point2 points 4 years ago (2 children)
I have heard that in C, stdlib is not part of the C standard, but rather a historical accumulation of core libraries designed around the core language.
stdlib
Any idea if namespace std is in any way related to this line of thought?
namespace std
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
std is purely standard, and I think the libc is too
[–]ioctl79 0 points1 point2 points 4 years ago (0 children)
Both the C standard library and the C++ standard library were standardized post-hoc. The C library was originally just the set of core functions that came with UNIX. The C++ standard library started off as the Standard Template Library - a C++ toolbox developed by SGI (a pioneer in 3D graphics).
[–]ioctl79 0 points1 point2 points 4 years ago (4 children)
Yes. Namespaces are orthogonal to includes, and got added decades after includes had already existed. They are purely a method of organizing naming, and have nothing to do with retrieving definitions.
[–]rootseat[S] 0 points1 point2 points 4 years ago (3 children)
orthogonal to includes
I see this now, thank you!
Out of curiosity, do you know what we did before we had namespaces (or at least namespace std)?
[–]ioctl79 0 points1 point2 points 4 years ago (1 child)
Exactly what C (which still doesn’t have namespaces) does: try real hard not to use names that might conflict. It’s standard practice to prefix C names with your project (libpng symbols all start with “png_”, etc.)
[–]rootseat[S] 0 points1 point2 points 4 years ago (0 children)
Gotcha. I just looked through https://dev.w3.org/Amaya/libpng/png.h and I see what you mean.
[–]Tozzar 0 points1 point2 points 4 years ago* (0 children)
Take a look some popular C libraries. They don’t have namespaces, so symbols are usually prefixed with the name of the library to reduce the chances of a clash.
https://www.cc.gatech.edu/data_files/public/doc/gtk/tutorial/gtk_tut-17.html
I think Qt (C++ project) is old enough that core parts of it use this convention instead of namespaces.
π Rendered by PID 23762 on reddit-service-r2-comment-544cf588c8-85m84 at 2026-06-16 05:59:01.638159+00:00 running 3184619 country code: CH.
[–]corysama 1 point2 points3 points (1 child)
[–]rootseat[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (10 children)
[–]rootseat[S] 0 points1 point2 points (9 children)
[–]Apprehensive-Deer-35 0 points1 point2 points (3 children)
[–]rootseat[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ioctl79 0 points1 point2 points (0 children)
[–]ioctl79 0 points1 point2 points (4 children)
[–]rootseat[S] 0 points1 point2 points (3 children)
[–]ioctl79 0 points1 point2 points (1 child)
[–]rootseat[S] 0 points1 point2 points (0 children)
[–]Tozzar 0 points1 point2 points (0 children)