@ -4,10 +4,12 @@
# include <string>
# include <iostream>
# include <sstream>
# include <vector>
//convert string to double
// @return bool indicating success
bool toDecimal ( std : : string value , double & float_var ) {
bool toDecimal ( const std : : string value , double & float_var ) {
std : : istringstream stream ( value ) ;
stream > > std : : noskipws > > float_var ; // noskipws considers leading whitespace invalid
@ -17,7 +19,7 @@ bool toDecimal(std::string value, double& float_var) {
//convert string to integer
// @return bool indicating success
bool toInt ( std : : string value , int & int_var ) {
bool toInt ( const std : : string value , int & int_var ) {
std : : istringstream stream ( value ) ;
stream > > std : : noskipws > > int_var ; // noskipws considers leading whitespace invalid
@ -44,4 +46,20 @@ bool toBool(std::string value, bool& bool_var) {
}
//convert string to vector
// @return bool indicating success
bool toVector ( const std : : string value , std : : vector < std : : string > & vec_var , char delimiter ) {
std : : istringstream stream ( value ) ;
std : : string item ;
while ( std : : getline ( stream , item , delimiter ) ) {
vec_var . push_back ( item ) ;
}
//if all those fail then the value isn't a boolean so successes fails
return false ;
}