Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 73791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:15:25+00:00 2026-05-10T20:15:25+00:00

I am working on a large project that uses the STL and have a

  • 0

I am working on a large project that uses the STL and have a question about your preferred way to organise your STL #includes.

  • Do you prefer to #include each header in the source file it is used. For example, if both foo.cpp and bar.cpp require std::string, then both will #include <string>.
  • Do you prefer to have a single header file that includes all the STL headers your project uses (i.e. add them to the MS ‘stdafx.h’ pre-compiled header).

The advantage of the first method is that the .cpp file is an independent unit and can be used in a different project without having to worry that you’re missing a #include. The advantages of the second method is that you can take use your compilers pre-compiled header support plus you can wrap STL #includes in pragmas that disable some warnings (for example, some Boost headers will cause warnings when compiling at level 4).

Which do you prefer to use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:15:25+00:00Added an answer on May 10, 2026 at 8:15 pm

    I only include the header files that are really needed in every source, and not ‘catch all’ headers, to keep dependencies (and hence compile times) as low as possible.

    Precompiled headers can work irrespective of this (i.e. I rely on precompiled headers to speed up the compiling process, not to get declarations). So even if something gets declared via the included precompiled headers, I still include the ‘regular’ header, which will get skipped by the include guard mechanism and won’t add anything significant to the compile times.

    As precompiled headers are a compiler specific thing. Optimizing / changing precompiled headers should have no effect on the correct functioning of the code in my opinion.

    The main advantage of having dependencies as low as possible is that refactoring gets easier (or rather: feasible)

    Great book on all this is Large Scale C++ Design from Lakos

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started working on a very large C++ project that, after completing
I am working in Java on a fairly large project. My question is about
I am working on a project that does a large amount of hashing, signing,
I'm working on a project with a rather large Oracle database (although my question
We are working on a large project with a measure of new/modified GUI functionality.
I'm working with a large (270+ project) VS.Net solution. Yes, I know this is
I am working on a large C++ project in Visual Studio 2008, and there
I'm working on a rather large project, and its unlikely will catch everything. I've
We're a distributed team of 5 developers working on rather large integrations project. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.