Solved

#include ?

Posted on 2004-04-26
4
196 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
ID: 10921519
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
ID: 10921545
<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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 107
matchUp  challenge 6 53
has77  challenge 9 73
matchUp  challenge 9 94
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

863 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

23 Experts available now in Live!

Get 1:1 Help Now