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 6683053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:46:36+00:00 2026-05-26T04:46:36+00:00

If I have a class A which uses iostream, should I put the include

  • 0

If I have a class A which uses iostream, should I put the include statement of iostream in A.h or A.cpp?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T04:46:36+00:00Added an answer on May 26, 2026 at 4:46 am

    This is an area of some controversy. My own preference is that each header should be able to stand alone, so if it needs other headers, it includes them. In other words, if client code is going to need to include <iostream> (or whatever) anyway, your header should handle that for them. OTOH, if the user of the iostream is strictly hidden so the client code doesn’t need to include it at all, then it should only be included in the implementation file.

    In many cases (especially where the header is open to frequent change), you’d prefer to avoid including it in the header. In such cases, the PImpl idiom can be useful to get the dependency out of the header.

    If you do need to include <iostream>, do your clients a favor and consider whether you can #include <iosfwd> instead of <iostream> though. This can improve compile time a fair amount.

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

Sidebar

Related Questions

I have the following class which uses BinaryReader internally and implements IDisposable. class DisposableClass
I have a container class which uses boost::optional to hold the value. Here is
I have an application App1 which defines class A and uses instances of this
I have some logic, which defines and uses some user-defined types, like these: class
I have a class which uses a list for passing to ssrs and for
I have some class which uses boost singleton. It calls some function from own
I have a class which uses a HashSet and I want the class implement
I have a class which uses a method in user32.dll: [System.Runtime.InteropServices.DllImport(user32.dll)] private static extern
PROBLEM: I have a Child class which uses DataContractSerialization and raises a Changed event
I have written a helper class which uses the Action - delegate as method

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.