1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#ifndef __CM_SSTREAM__
#define __CM_SSTREAM__
#if 0
//#ifndef MSVC
#include <string>
#include <cstdio>
#include <strstream>
#include <algorithm>
namespace std {
class ostringstream
{
public:
ostringstream (const string & str = "")
: buffer(str) {}
const string & str() const
{
return buffer;
}
void str (const string & new_string)
{
buffer = new_string;
}
ostringstream & operator<< (const string & item)
{
buffer += item;
return *this;
}
ostringstream & operator<< (int item)
{
char temp[100];
sprintf (temp, "%d", item);
buffer += temp;
return *this;
}
ostringstream & operator<< (unsigned int item)
{
char temp[100];
sprintf (temp, "%u", item);
buffer += temp;
return *this;
}
ostringstream & operator<< (char item)
{
buffer += item;
return *this;
}
ostringstream & operator<< (double item)
{
char temp[1000];
sprintf (temp, "%g", item);
buffer += temp;
return *this;
}
private:
string buffer;
};
class istringstream
{
friend istringstream & getline (istringstream &, string &, char = '\n');
public:
istringstream (const string & str = "")
: buffer (str.c_str(), str.length()) {}
template <class T>
istringstream & operator>> (T & item)
{
buffer >> item;
return *this;
}
operator void * () const
{
return (void *) buffer;
}
private:
istrstream buffer;
};
inline istringstream & getline (istringstream & src_stream, string & str, char separator)
{
getline (src_stream.buffer, str, separator);
return src_stream;
}
} // End of namespace std
#endif
#endif
|