Q: char, wchar_t and operator << overloading

S

Suman

Hello All,

Given a structure:
struct s {
char *name;
wchar_t *surname;
};

I wish to define a friend function for the above struct:
std::eek:stream& operator<<(std::eek:stream& out, const s& x);
or whatever suitable stream it should take, which would
print both members.So I can write stuff like:

s my_struct;
// fill it up
....
std::cout << my_struct;

AFAIK wchar_t requires wostream. Which is the root of
the problem. I can definitely convert the wchar_t stuff to some
multibyte char sequence and go through ostream. Does a
better alternative exist?

Regards,
Suman.
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

Suman said:
Hello All,

Given a structure:
struct s {
char *name;
wchar_t *surname;
};

I wish to define a friend function for the above struct:
std::eek:stream& operator<<(std::eek:stream& out, const s& x);
or whatever suitable stream it should take, which would
print both members.So I can write stuff like:

s my_struct;
// fill it up
...
std::cout << my_struct;

AFAIK wchar_t requires wostream. Which is the root of
the problem. I can definitely convert the wchar_t stuff to some
multibyte char sequence and go through ostream. Does a
better alternative exist?

Regards,
Suman.

The short answer is "no". The long answer is "No, there is no other
solution. And that conversion can be extremely complex.". Sorry.


K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top