92

Does documentation for C++ exist in Linux? I want something like the man pages of C. For example, docs for string, stl, iostream, ifstream, etc.?

7
  • 6
    Are you looking for a resource not on the internet? Mar 14, 2011 at 1:10
  • 1
    You can just search up "c++ <feature you want to know about>" Most of the time this will result in a page from cplusplus.com
    – flight
    Mar 14, 2011 at 1:11
  • 17
    Just yesterday I found myself wishing libstdc++ provided manpages rather than forcing me to use a web browser to find documentation.
    – sarnold
    Mar 14, 2011 at 1:42
  • 2
    To the commenters above, have you ever done development somewhere that you had difficult or impossible access to the internet? Imagine that your only access is 25 to 75 steps away, on a machine shared by other people that use it throughout the day. And this is the only place that you can access the internet. No wifi or cell phone is available. And no modifications to the network are possible.
    – Pulseczar
    Aug 14, 2017 at 20:40
  • 10
    For other readers, you can clone this repo then ./configure and make install on your system. It will install documentation from cppreference.com available via your man command ie. man std::queue. Quite handy.
    – haxpor
    Jul 5, 2018 at 15:59

8 Answers 8

70

If you use the "normal" libstdc++ shipped with g++, its documentation is available online here.

Most Linux distributions make it also available offline as a particular package; for Debian-derived distros, for example, it's libstdc++-6-<version>-doc (e.g. on my Ubuntu machine I have libstdc++-6-4.4-doc installed). In general the documentation will be put somewhere like /usr/share/doc/libstdc++-6-4.4-doc.

This about implementation-specific documentation; for compiler-agnostic docs, instead, many sites on the Internet provide reference documentation for the standard library.

One of the most referenced is nowadays cppreference.com, that is actively maintained, tends to be very faithful to the standard and shows well the differences between the various standard versions; it can be a bit intimidating to newbies, though.

cplusplus.com historically was one of the most used (especially as it is very "liked" by search engines), but was known to contain several errors or incorrect simplifications; I don't know if it got any better in these last years.

Also, the C++ library section on msdn.microsoft.com has got much better in the recent years in separating what are the Microsoft-specific details from what the standard dictates.

Finally, if you want precision up to the paranoia, the ultimate normative document is the C++ standard, that is sold from ISO, ANSI and BSI (for a quite high price); there are however several drafts available for free, which are more than good enough for "casual use".

5
  • 1
    Thank you! It was a perfect answer to my doubt... I was searching it for a long time, but i couldnt find any answer like this...
    – fpointbin
    Mar 14, 2011 at 1:49
  • 24
    IMO the best compiler-agnostic reference is en.cppreference.com/w it is mostly accurate, and it shows whether any given feature is C++03 or C++11 Aug 7, 2012 at 11:00
  • 7
    @FabioFracassi Yes, and in november 2014 the offline version of the documentation at cppreference.com was added to Ubuntu Vivid: apt-get install cppreference-doc-en-html.
    – zwets
    Oct 9, 2015 at 7:05
  • 1
    IMHO this is a good resource too github.com/aitjcize/cppman
    – Calamar
    Apr 22, 2016 at 19:01
  • There's also a set of C++ man pages that can be copied from OpenSolaris, but they're incomplete to say the least. Nov 27, 2019 at 1:01
42

In Ubuntu, after installing libstdc++-6-x.x-doc, these docs are available via man, examples(libstdc++-4.8-doc)

man std::list
man std::weak_ptr
man std::ios_base

To get a list of these entries, use

apropos -r '^std' | vi -

This command gets all man entries beginning with std and sends them to vi.

==========

Update: as of libstdc++-4.8-doc, the prefix is std:: instead of std_.

3
  • Doesn't appear to work in Ubuntu 12.04. I.e. I installed this package, but your example commands don't give the manual pages.
    – Ruslan
    Mar 6, 2014 at 7:42
  • 1
    @Ruslan I have updated my answer, the prefix changed to std:: instead of std_ Mar 6, 2014 at 11:23
  • Works for me on Ubuntu 16.04, using the man std::list syntax.
    – BeeOnRope
    Jan 17, 2017 at 2:19
14

cppman is a C++ manpage formatter available on Github.

On request, it generates manpages from cplusplus.com, and it is quite good at it. Your manpage viewer will be cppman instead of man, though, and you still need to be online.

3
  • 3
    You can now cache all of them for off-line viewing. It takes approx 20 minutes.
    – Dilawar
    Apr 16, 2013 at 19:29
  • Cppman has an option (-m true) to export its documents to man.
    – John P
    Aug 18, 2015 at 7:23
  • 1
    And the command for offline caching, after the installation1 or installation2 is simply cppman -c Jun 10, 2017 at 10:31
8

Install the man pages:

$ sudo apt-get install libstdc++6-4.4-doc
2
  • Assuming your distribution uses apt for package management.
    – Sam Miller
    Mar 14, 2011 at 1:17
  • 6
    Just for the sake of precision, these are not manpages, but HTML docs (put in /usr/share/doc/libstdc++4.4-doc). Mar 14, 2011 at 1:18
6

The C++ standard library is documented at http://www.cplusplus.com/reference/. Your implementation might bring it's own documentation. For example libstdc++ from the GNU Compiler Collection is documented at http://gcc.gnu.org/onlinedocs/libstdc++/. Look into the source distribution of the specific library to find out if and where the documentation is.

1
  • Unfortunately, cplusplus.com is really outdated in the meantime.
    – tommsch
    Jun 24, 2021 at 10:38
4

On Ubuntu an offline copy of the excellent documentation at http://cppreference.com is available in the packages cppreference-doc-en-html (HTML) and cppreference-doc-en-qch (Qt Help format).

To install:

sudo apt-get install cppreference-doc-en-html
5
  • 1
    *Not available as of Nov 24, 2016.
    – silent_dev
    Nov 24, 2016 at 14:27
  • 2
    I installed cppreference-doc-en-html in Ubuntu, but how should I use it? Doing man fputs will open Linux Programmer's Manual and not cppreference documentation. In other words, where are cppreference docs stored? Apr 8, 2018 at 6:43
  • 2
    @Sergio dpkg -L cppreference-doc-en-html will tell you the contents of the package.
    – zwets
    Apr 9, 2018 at 5:29
  • @zwets Thank you! That solved the problem now I can access the documentation. Apr 9, 2018 at 6:31
  • How do you access them in linux ?
    – cassepipe
    May 1, 2022 at 11:56
2

On RHEL 6 the package libstdc++-docs installs documentation in /usr/share/doc AND man pages:

sudo yum install -y libstdc++-docs

now I can: man std::string

for example.

1

You'll want to pay close attention to the version of your compiler; on recent linux distributions you're likely using g++ v4.3, or maybe v4.4, but some of the newer C++0x features are in g++ v4.5, so depending on the features you are playing with, you may run into issues on that front.

Not the answer you're looking for? Browse other questions tagged or ask your own question.