473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

strange behaviour of wcout used with CStringW

Hello, All!

i admit that it's better to ask questions connected with atl/mfc classes in
special newsgroups, but seems like people there are interested more in
discussing stuff like MFC GUI than C++ 8-/, so i'll better ask here too..

CStringW is a class in atl/mfc dealing with strings 8-]. the only typecast
operator i found is to PCXSTR that is LPCWSTR that is simply "const unsigned
short*" (wchar_t is unsigned short).
wcout accepts wchar_t* strings. so i expect i can ouptut that CStringW into
wcout using <<, or compiler should generate some error.
but it does funny thing - it prints address of string instead of it - << for
const void * is called. even more funny - if i explicitly cast to the
pointer all is well. i tried different types but no one causes printing
address.
such behaviour could be possible if << is defined for CString and it's
broken, but i found no such definition.
i have no ideas what else can be causing this behaviour.. if anybody have
ideas what's happening or how to investigate it - please help.

here's code causing problems:

CStringW myStr(L"A");

std::wcout<<myStr<<std::endl;
std::wcout<<CStringW::PCXSTR(myStr)<<std::endl;
std::wcout<<(const unsigned short*)(myStr)<<std::endl;

generated output is

00325CF0
A
A

i even tried to debug in disassembly - it appears that in all three cases
cast of CStringW to "unsigned short const *" is called, then in first case
it goes into "const void*" output, in other two - into normal string
output..

With best regards, Alex 'killer_storm' Mizrahi.
Jul 22 '05 #1
2 3042
"Alex Mizrahi" <ud******@hotmail.com> wrote in message
news:31*************@individual.net...
Hello, All!

i admit that it's better to ask questions connected with atl/mfc classes in special newsgroups, but seems like people there are interested more in
discussing stuff like MFC GUI than C++ 8-/, so i'll better ask here too..

CStringW is a class in atl/mfc dealing with strings 8-]. the only typecast
operator i found is to PCXSTR that is LPCWSTR that is simply "const unsigned short*" (wchar_t is unsigned short).


[snip]

Questions that asssume knowledge of classes and other types that aren't a
part of standard C++ are off-topic. But you can make your question on-topic
by providing the relevant definitions. In this case, the class definition of
CStringW (and anything non-standard it uses that's relevant to the question)
would probably be enough.

DW

Jul 22 '05 #2
(message (Hello 'Jack)
(you :wrote :on '(Thu, 09 Dec 2004 23:13:31 -0600))
(
CStringW is a class in atl/mfc dealing with strings 8-]. the only
typecast


JK> CStringW is completely off-topic here. Unless you are going to
JK> provide the interface and implementation details, kindly go
JK> elsewhere.

ok, here is it w/o microsoft classes:

#include <iostream>

typedef const wchar_t* LPCWSTR;

struct mystr_t {
operator LPCWSTR()
{
return L"a";
}
};

void fun(const void* ptr)
{
std::cout<<"const void*"<<std::endl;
}

void fun(const wchar_t * ptr)
{
std::cout<<"const unsigned short*"<<std::endl;
}

int main()
{
mystr_t myStr;

fun (myStr);

std::wcout<<myStr<<std::endl;
std::wcout<<LPCWSTR(myStr)<<std::endl;

}

and if your compiler knows nothing about wcout, this can be any wostream,
where wostream is defined as

typedef basic_ostream<wchar_t, char_traits<wchar_t> > wostream;

output is

const unsigned short*
0041413C
a
there are following << operators defined for ostream:

_Myt& operator<<(const void *_Val)

template<class _Elem, class _Traits> inline
basic_ostream<_Elem, _Traits>& __cdecl operator<<(
basic_ostream<_Elem, _Traits>& _Ostr, const _Elem *_Val)

why does it ignore second one?

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
(prin1 "Jane dates only Lisp programmers"))
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
3
by: Steven T. Hatton | last post by:
There's probably something obvious I'm missing here, but I can't seem to figure out how to get this to work: ostream_iterator<wstring, wchar_t>(wcout,"\n")); When I try to compile it, I get an...
5
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
11
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's...
0
by: Ralf Goertz | last post by:
Hi, consider the following program loc.cc #include <iostream> #include <fstream> #include <string> #include <locale> using namespace std;
1
by: iwongu | last post by:
Hi, I have a question about std::wcout and its underlying C functions. According to C99, a stream have an orientation type that is one of byte-oriented or wide-one, and it is determined by the...
2
by: interec | last post by:
I have a simple program in which I want to read a wstring using wcin and then output the same string using wcout. The program takes a few words separated by spaces as input. The problem is that...
2
by: Ralf Goertz | last post by:
Hi, can I mix output to cout and wcout? It seems that if I write to cout first it works fine but if I start with wcout the output to cout vanishes. I assume that is has to do with the...
44
by: Ioannis Vranos | last post by:
Has anyone actually managed to print non-English text by using wcout or wprintf and the rest of standard, wide character functions?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.