Created
February 24, 2012 02:59
-
-
Save shanna/1896874 to your computer and use it in GitHub Desktop.
Casting to and from strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
template<typename T> | |
T string_to(const std::string& p_string) { | |
std::istringstream iss(p_string); | |
T x; | |
iss >> x; | |
return x; | |
} | |
template<typename T> | |
std::string to_string(const T& p_val) { | |
std::ostringstream oss; | |
oss << p_val; | |
return oss.str(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment