Solved

#include ?

Posted on 2004-04-26
4
197 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

825 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