1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are --- 32 unchanged lines hidden (view full) --- 41#include <string> 42#include <sstream> 43#include <stdexcept> 44 45 46template<typename T> 47T fromString(const std::string& s, 48 std::ios_base& (*f)(std::ios_base &) = std::dec) |
49{ 50 std::istringstream is(s); 51 T t; 52 53 if (!(is >> f >> t)) { 54 throw std::runtime_error("Cannot convert string"); 55 } 56 57 return t; 58} 59 60#endif /* UTILS_H */ |