RetroX
|
|
Posted on: February 24, 2010, 01:47:59 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Something useful for ENIGMA:
std::ostream &operator <<(std::ostream &outstream,__variant &variable) { if (variable.type) { return outstream << variable.doubleval; } return outstream << variable.stringval; } std::istream &operator >>(std::istream &instream,__variant &variable) { char c,c2; c=instream.get(); if (c>=48 && c<=57) { instream.putback(c); return instream >> variable.doubleval; } else if (c==46) { c2=instream.get(); if (c2>=48 && c2<=57) { instream.putback(c2); instream.putback(c); return instream >> variable.doubleval; } } instream.putback(c); return instream >> variable.stringval; } You probably should add a typecast operator for var to cast to __variant.
This is from r3's source, though, so, IDK what you've changed.
Also, because I wouldn't know, would this also work for iostream, fstream, and stringstream because they are inherited from istream and ostream, or would it not because this is defined after that?
|
|
« Last Edit: February 24, 2010, 01:52:48 pm by RetroX »
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
Josh @ Dreamland
|
|
Reply #1 Posted on: February 24, 2010, 07:38:55 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Does... that work? It should error that your function should be a member of std::ostream rather than declared in the global scope...
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #3 Posted on: February 25, 2010, 08:23:50 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Duly noted.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
RetroX
|
|
Reply #5 Posted on: March 04, 2010, 06:38:54 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Additionally, here's something else that might be useful:
// Operators for strings (addition) string &operator +(string &str1,string &str2) { string temp=str1; return temp+=str2; } string &operator +(string &str1,cstring str2) { string temp=str1; return temp+=str2; }
// Operators for strings (comparison) bool operator ==(string &str1,string &str2) { string temp=str1; return (temp.compare(str2)); } bool operator ==(string &str1,cstring str2) { string temp=str1; return (temp.compare(str2)); }
// Operators for strings (comparison) bool operator !=(string &str1,string &str2) { return !(str1==str2); } bool operator !=(string &str1,cstring str2) { return !(str1==str2); } Simple operators for strings.
|
|
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
Josh @ Dreamland
|
|
Reply #6 Posted on: March 04, 2010, 06:44:39 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
String already defines those... And then some...
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|
|
RetroX
|
|
Reply #11 Posted on: March 04, 2010, 09:19:37 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Could you implement those operators for char *s?
string operator+(string str,char *str2) { return str+const_cast<const char*>(str2); } ?
|
|
« Last Edit: March 04, 2010, 09:36:53 pm by RetroX »
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #14 Posted on: March 05, 2010, 09:33:35 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
He's thinking about 'situations where you need to quote "' + "that's" + '," or other situations requiring both "' + " and '".
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|