Re: [Dev-C++] String << operator overloaded (using template)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-07-15 00:48:55
|
I am curious. Does the same code work if you try to use
more than one "<<"
in a statement?
e.g.
someString << someInt << someFloat;
the line of code that is not doing what it is supposed to
do is as follows.
(temp is a string, ROOT_DIR = const char == "..", dir_names
= map of
strings, DIR_SEP = const char == "\\" under windows, "/"
under *NIX)
temp << ROOT_DIR << DIR_SEP << dir_names[dir] << DIR_SEP <<
filename;
----- Original Message -----
From: "Jaap de Wolff" <wo...@ne...>
To: <ci...@ya...>; "Dev-Cpp Mailing List"
<dev...@li...>
Sent: Monday, July 14, 2003 8:25 AM
Subject: RE: [Dev-C++] String << operator overloaded (using
template)
> At my place it works.
> I made a class myclass to test, see below.
>
>
> -----Original Message-----
> >From: David McKen [mailto:ci...@ya...]
> >Sent: Sunday, July 13, 2003 8:02 PM
> >To: Dev-Cpp Mailing List
> >Subject: [Dev-C++] String << operator overloaded (using
template)
> >
> ..
>
> #include <string>
> #include <sstream>
> #include <iostream>
>
>
> class myclass {
> public:
> myclass (int n) { member = n; }
> private:
> int member;
> friend std::iostream& operator<< (std::iostream& str,
class myclass
> &val);
> };
>
> std::iostream& operator<< (std::iostream& str, class
myclass &val){str <<
> val.member;return str;}
>
>
> template <class in_type>
> std::string& operator<< (std::string& output, in_type&
data)
> {
> std::stringstream ss;
> ss << data;
> ss >> output;
> return output;
> }
>
>
> void main()
> {
> std::stringstream ss;
> std::string sout;
> myclass hulp (15);
> sout << hulp;
> std::cout << sout;
> }
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps1
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
|