473,322 Members | 1,562 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,322 software developers and data experts.

Q: char, wchar_t and operator << overloading

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
1 2413

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Victor | last post by:
Anyone knows how to write a virtual function for operator<< ? I have a base class and some public derived class from it. For the derived class, I hope they can use << to output their different...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
3
by: Robert Wierschke | last post by:
Hi I want to overload the operator<< for a class Vector. class Vector { double x; double y; double z;
5
by: Ian Lazarus | last post by:
Hello, My question is whether it is possible to avoid assignment on the left hand side of an overloaded operator << expression, as in the code below. Without the assignment, the compiler...
25
by: Steve Richter | last post by:
is it possible to overload the << operator in c# similar to the way it is done in c++ ? MyTable table = new MyTable( ) ; MyTableRow row = new MyTableRow( ) ; row << new MyTableCell( "cell1 text...
3
by: peak | last post by:
I have this code that I am using to create a heap template <class t> void BinaryHeap<t>::insert( const T &x) { int hole = ++ currentSize; for ( ; hole > 1 && x < array;hole /= 2) arrsy = arrsy;...
2
by: Harry | last post by:
Hi all, I am writing a logger program which can take any datatype. namespace recordLog { enum Debug_Level {low, midium, high}; class L { std::ofstream os; Debug_Level cdl; const...
5
by: TOMERDR | last post by:
Hi, I was requested to write a code similar to this: CArchive ar; //Not mfc CArchive..... .... void * vp = &XXX; // any object. ar << vp, sizeof(XXX);
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.