Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
string_utils.h
Go to the documentation of this file.
1 /*
2  * string_utils.h
3  *
4  * LICENSE HERE
5  *
6  * Created on: 2016-08-29
7  * Author: Rick Valenzano
8  */
15 #ifndef STRING_UTILS_H_
16 #define STRING_UTILS_H_
17 
18 #include <vector>
19 #include <sstream>
20 #include <iostream>
21 #include <stdlib.h>
22 
29 std::string int_to_string(int i);
30 
37 std::string double_to_string(double d);
38 
46 void split(const std::string &s, std::vector<std::string> &tokens, char delim);
47 
55 template<class T>
56 std::string vec_to_string(const std::vector<T> &vec);
57 
58 // Templated function implementations
59 template<class T>
60 std::string vec_to_string(const std::vector<T>& vec)
61 {
62  std::stringstream s;
63  s << "[";
64  for(unsigned i = 0; i < vec.size(); i++) {
65  s << vec[i];
66  if(i != vec.size() - 1)
67  s << " ";
68  }
69  s << "]";
70  return s.str();
71 }
72 
73 #endif /* STRING_UTILS_H_ */
std::string vec_to_string(const std::vector< T > &vec)
Definition: string_utils.h:60
void split(const std::string &s, std::vector< std::string > &tokens, char delim)
std::string int_to_string(int i)
Definition: string_utils.cpp:17
std::string double_to_string(double d)
Definition: string_utils.cpp:24