Solved

#include ?

Posted on 2004-04-26
4
195 Views
Last Modified: 2013-11-20
Why when I use #include <iostream.h> everything is fine... it prints "Hello World"
But if I use #include <iostream> it prints numbers probably an Address ?

#include <afxwin.h>
#include <iostream> // problem


int main()
{
      CString s1("Hello World");

      std::cout << s1;

      return 0;
}
0
Comment
Question by:Prog_
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Use

    std::cout << (LPCTSTR) s1;

STL knows nothing about CString, so you will have to force a conversion, otherwise the behaviour will be undefined (as you already noticed).

0
 
LVL 14

Expert Comment

by:wayside
Comment Utility
<iostream.h> is older and has Microsoft-specific stuff in it, so it knows what to do with a CString.

<iostream> is pure STL, and doesn't know anything about MFC classes like CString. And CString doesn't have an operator<< for cout. But you should be able to cast it to do what you want:

CString s1("Hello World");
std::cout << (LPCTSTR) s1;
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now