|
#ifndef _STRING_ELEMENT_H
#define _STRING_ELEMENT_H
#include <string>
#include <sstream>
class StringElement {
private:
template<typename T> std::string ToString(T &val) {
std::stringstream ss;
ss << val;
std::string retVal;
ss >> retVal;
return retVal;
};
std::string _value;
public:
StringElement(int i) : _value(ToString<int>(i)) {
};
StringElement(double d) : _value(ToString<double>(d)) {
};
StringElement(char c) : _value(ToString<char>(c)) {
};
StringElement(char *cp) : _value(cp) {
};
StringElement(const std::string s) : _value(s) {
};
StringElement(long l) : _value(ToString<long>(l)) {
};
StringElement(float f) : _value(ToString<float>(f)) {
};
StringElement(short s) : _value(ToString<short>(s)) {
};
StringElement(bool b) : _value(ToString<bool>(b)) {
};
operator std::string() const {
return _value;
};
};
#endif _STRING_ELEMENT_H
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software engineer, as well as a research student at The Hebrew University. I love coding, math, computer theory, reading, tennis, guitar, swimming, animals, and - most importantly - my wife and family.