Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SplitString.h
Go to the documentation of this file.
1 #ifndef _SplitString_
2 #define _SplitString_
3 
4 #include <sstream>
5 
6 template<typename T>
7 void SplitString(string str, vector<T> &vec, const string &delim=" ")
8 {
9  if(str.length()==0)return;
10  unsigned int cutAt;
11  while( (cutAt = str.find(delim)) != (unsigned int)str.npos ){
12  if(cutAt > 0){
13  std::stringstream ss(str.substr(0,cutAt));
14  T t;
15  ss>>t;
16  vec.push_back(t);
17  }
18  str = str.substr(cutAt+1);
19  }
20  if(str.length() > 0){
21  std::stringstream ss(str);
22  T t;
23  ss>>t;
24  vec.push_back(t);
25  }
26 }
27 
28 #endif
char str[256]
void SplitString(string str, vector< T > &vec, const string &delim=" ")
Definition: SplitString.h:7