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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:15:08+00:00 2026-06-01T17:15:08+00:00

I have two files, my_program.cpp and its header my_program.h . my_program.cpp contains only this:

  • 0

I have two files, my_program.cpp and its header my_program.h.

my_program.cpp contains only this:

#include "my_program.h"
using namespace std;

my_program.h contains a pointer to a function which returns a wstring, as follows:

using namespace std;
typedef wstring (*my_function)(wstring, int, int, int, int);

The program doesn’t compile in this state (stops at typedef… saying that ISO C++ forbids declaration of ‘wstring’ with no type) but if I add #include <iostream> before #include "my_program.h" in the .cpp file, the program miraculously compiles.

Why does this happen? I just hope I didn’t make a foolish mistake and I’m now going to be laughed at.

  • 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-06-01T17:15:09+00:00Added an answer on June 1, 2026 at 5:15 pm

    You really should include <string>.

    From the sound of things, your compiler’s <iostream> happens to include <string>, so it works, but on a different compiler it may not. C++ allows a standard header to include other standard headers, but doesn’t require it. In some cases, you get only a declaration of the class, so some things work, and others don’t.

    At least in my experience, this is also an issue that’s likely to change from one version of a compiler to the next, so even if you don’t intend to port to anything else, your code may quit working just due to a seemingly trivial upgrade unless you include the right header.

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

Sidebar

Related Questions

this is my situation: I have two org.w3c.dom.Document created from two xml files. What
Lets say I have files: Libs: one.cpp, one.h two.cpp, two.h three.cpp, three.h Program: program.cpp
I have a namespace that I am currently using in two classes. When I
Say I have two .cpp files: oranges.cpp and basket.cpp . They have the classes
Lets say I have 3 files: add.h, add.cpp and main.cpp. This is a common
I have two code files, one contains my WinMain() function, and all functions related
I have a very small c++ program that consists of two files: main.cpp and
In my iPhone app, I have two plist files to store Themes. One is
I have two files (f1 and f2) containing some text (or binary data). How
I have two files with slight differences. A normal diff will show me the

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.