Skip to content

Instantly share code, notes, and snippets.

@shanna
Created February 24, 2012 02:59
Show Gist options
  • Save shanna/1896874 to your computer and use it in GitHub Desktop.
Save shanna/1896874 to your computer and use it in GitHub Desktop.
Casting to and from strings.
#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