By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Q: char, wchar_t and operator << overloading

P: n/a
Hello All,

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

I wish to define a friend function for the above struct:
std::ostream& operator<<(std::ostream& 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.

Sep 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Suman wrote:
Hello All,

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

I wish to define a friend function for the above struct:
std::ostream& operator<<(std::ostream& 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

Sep 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.