Solved

#include ?

Posted on 2004-04-26
4
200 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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).
Suggested Courses

636 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