473,785 Members | 3,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<<myS tr<<std::endl;
std::wcout<<CSt ringW::PCXSTR(m yStr)<<std::end l;
std::wcout<<(co nst 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 3075
"Alex Mizrahi" <ud******@hotma il.com> wrote in message
news:31******** *****@individua l.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<<"con st void*"<<std::en dl;
}

void fun(const wchar_t * ptr)
{
std::cout<<"con st unsigned short*"<<std::e ndl;
}

int main()
{
mystr_t myStr;

fun (myStr);

std::wcout<<myS tr<<std::endl;
std::wcout<<LPC WSTR(myStr)<<st d::endl;

}

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

typedef basic_ostream<w char_t, char_traits<wch ar_t> > wostream;

output is

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

_Myt& operator<<(cons t 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
2362
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. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
3
4750
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 error telling me it doesn't like the char. wcout.widen('\n') doesn't work here because it wants a string. Is there a way to make this work? -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed
5
3110
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 showing a list of jobs from the database. When the main form loses focus and the user clicks the 'Close' button, I kept receiving error 2585 (This action cannot be carried out whilst processing a form or report event). This was tracked down to...
11
2501
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 support team for more information. However I'm not purposely requesting that the Runtime terminate in an "unusual way." The line that is causing me headaches is:
0
1932
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
3607
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 first using C function on that stream. And the specific orientation functions should not be applied to the stream that have other orientation.
2
8395
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 only the first word is outputted. Everything after the first space seems to be lost in the output. My OS is redhat hat linux 4 ES. gcc 3.4.6. How do I fix this and why its not working? Thanks Code
2
7779
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 initialization of standard output, right? #include <iostream> using namespace std;
44
4386
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
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.