Urgent! operator (ostream) Not anymore
I am at public library but I need to know what code is exactly called when executing. I need function definition.
ostream &operator<<(ostream &os, const float &fVal);
And please hurry up.
[Edited by - ffx on November 12, 2004 9:15:41 AM]
if I'm understanding the question correctly, you want the code for that operator? that's implementation specific, and with Microsoft implementations, I believe it's copyrighted
Since you demand a fast answer: GNU libstdc++, bits/ostream.tcc
Happy?
template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>:: operator<<(double __n) { sentry __cerb(*this); if (__cerb) { ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); try { _M_check_facet(this->_M_fnumput); const __numput_type& __np = *this->_M_fnumput; if (__np.put(*this, *this, this->fill(), __n).failed()) __err |= ios_base::badbit; } catch(...) { this->_M_setstate(ios_base::badbit); } if (__err) this->setstate(__err); } return *this; }
Happy?
Quote:Original post by antareus
I dunno if his homework will let him put all those underscores on there, Fruny. :)
Not my problem (technically, it's a "no", since only the compiler and standard library people are allowed to use them so). His question rubbed me the wrong way. I just hope he's up to snuff with locales, because that's where the magic's happening (that const __numput_type& __np thingy).
Quote:Original post by Fruny
Since you demand a fast answer: GNU libstdc++, bits/ostream.tcc
i knew that was going to come sooner or later [lol]
Quote:Original post by Fruny
Since you demand a fast answer: GNU libstdc++, bits/ostream.tcc
*** Source Snippet Removed ***
Happy?
Absolutely, only too late. Quite interesting code.
But thanks anyway.
Quote:Original post by antareus
I dunno if his homework will let him put all those underscores on there, Fruny. :)
Not my homework. I was trying to create system that would invoke operator<< for ostream class even when sent through pointer to some class. Got me? It is for my serialization article that I'm writing and I'm trying to make it as standard compatible as I can.
Idea is stream indpendant streaming.
oarchive ar;//..ignore initializationar << fVal;
This can either call ostream operator<< or ostream.write depending on archive type (text or binary).
Quote:Original post by ffxQuote:Original post by antareus
I dunno if his homework will let him put all those underscores on there, Fruny. :)
Not my homework. I was trying to create system that would invoke operator<< for ostream class even when sent through pointer to some class. Got me? It is for my serialization article that I'm writing and I'm trying to make it as standard compatible as I can.
Let me get this straight: you're writing an article when you can't be arsed to look up standard header sources in [google], and assume everybody else is your research monkey? I've seen enough badly written tutorials and articles made by newbies who post tutorials explaining how to create badly written code (the ones that horrify me the most are the ones that teach you how to use C to create security holes), and you need it now (and it's now "too late")? I'm sorry, but this screams of homework.
Quote:Idea is stream indpendant streaming.oarchive ar;//..ignore initializationar << fVal;
This can either call ostream operator<< or ostream.write depending on archive type (text or binary).
So, you're effectively creating a wrapper like so:
class oarchive{ std::ostream & os; bool binary;public: //... template < typename T > oarchive & operator<<( const T & value ) { if (binary) { os.write(reinterpret_cast<const char *>(&value),sizeof(T)); } else { os << value; } return *this; }};
?
Quote:Original post by MaulingMonkeyLet me get this straight: you're writing an article when you can't be arsed to look up standard header sources in [google], and assume everybody else is your research monkey? I've seen enough badly written tutorials and articles made by newbies who post tutorials explaining how to create badly written code (the ones that horrify me the most are the ones that teach you how to use C to create security holes), and you need it now (and it's now "too late")? I'm sorry, but this screams of homework.
Well if you want to know I've made serialization system for my last engine. It was similar to serialization system found in utpub432 (I got my inspiration from there). Then I decided to write article about serialization by showing my work but I didn't just copy and paste my source code. Instead, I browsed through tons of articles on web (e.g. codeproject) in order to write good system, not just some hack. I sent article to gamedev but I stopped it from publishing when I realized how many errors there are in there. If you want, I could send it to you.
I currently don't have a computer. I've moved to another town but I'll get one (computer, not town) in a matter of weeks. However, spending free time designing and by using public internet acess in my library I was designing my serialization system.
I just wanted to see what does operator << do for float data type, just that. Why is it too late? Its because I've thought of another solution in mean time.
Quote:
[qoute]oarchive ar;//..ignore initializationar << fVal;
This can either call ostream operator<< or ostream.write depending on archive type (text or binary).
So, you're effectively creating a wrapper like so:
class oarchive{ std::ostream & os; bool binary;public: //... template < typename T > oarchive & operator<<( const T & value ) { if (binary) { os.write(reinterpret_cast<const char *>(&value),sizeof(T)); } else { os << value; } return *this; }};
?
Not like that. Consider code :
ostream os(/* here goes archive type, binary, text or xml or any other*/);os << fVal;
My problem is that if user wanted to save to standard ofstream I need to call istream operator<< but if he wanted to save in binary I need to call member function write. You see my problem? Anyway, I've come to solution.Don't worry, I don't plan to release bad article. I've seen to many of those.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement