G
Gary Wessle
Hi
I wrote this routine below but getting the error below it which I
don't know how to fix.
thanks
//useful.h
/**
Reads data from file into a given type vector.
@param string full path to file containing the data
@param short int column number to return in a vector
@param char type of data s-string, d-double, i-int
...
@return vector<type_selected_as_above>
*/
template<class T>
vector<T> get_data(string, short, char);
****************************************************************
//useful.cpp
template<class T> vector<T> get_data(string s,
short sh,
char ch){
sh--;
ifstream in(s.c_str());
string line;
vector<string> vs;
vector<double> vd;
vector<int> vi;
while( getline(in, line) ){
stringstream input(line.c_str());
int j = 0;
switch (ch){
case 's':
string st;
while( input >> st)
if(sh == j++) vs.push_back(st);
case 'd':
double dt;
while( input >> dt)
if(sh == j++) vd.push_back(dt);
case 'i':
int it;
while( input >> it)
if(sh == j++) vi.push_back(it);
default:
cout << "type not known" << endl;
}
}
switch(ch){
case 's':return vs;
case 'd':return vd;
case 'i':return vi;
}
}
****************************************************************
int main(){
string f = "/data/home/activity.dat";
vector<string> vss = get_data(f, 1, 's'); //line 40 error
typedef vector<string>::iterator ITER;
ITER iterEnd = vss.end();
for (ITER iter = vss.begin(); iter != iterEnd; ++iter)
copy(iter->begin(), iter->end(), ostream_iterator<string>(cout, endl));
****************************************************************
main.cpp:40: error: no matching function for call to
'get_data(std::string&, int, char)'
main.cpp:46: error: no matching function for call to
'std:stream_iterator<std::basic_string<char, std::char_traits<char>,
I wrote this routine below but getting the error below it which I
don't know how to fix.
thanks
//useful.h
/**
Reads data from file into a given type vector.
@param string full path to file containing the data
@param short int column number to return in a vector
@param char type of data s-string, d-double, i-int
...
@return vector<type_selected_as_above>
*/
template<class T>
vector<T> get_data(string, short, char);
****************************************************************
//useful.cpp
template<class T> vector<T> get_data(string s,
short sh,
char ch){
sh--;
ifstream in(s.c_str());
string line;
vector<string> vs;
vector<double> vd;
vector<int> vi;
while( getline(in, line) ){
stringstream input(line.c_str());
int j = 0;
switch (ch){
case 's':
string st;
while( input >> st)
if(sh == j++) vs.push_back(st);
case 'd':
double dt;
while( input >> dt)
if(sh == j++) vd.push_back(dt);
case 'i':
int it;
while( input >> it)
if(sh == j++) vi.push_back(it);
default:
cout << "type not known" << endl;
}
}
switch(ch){
case 's':return vs;
case 'd':return vd;
case 'i':return vi;
}
}
****************************************************************
int main(){
string f = "/data/home/activity.dat";
vector<string> vss = get_data(f, 1, 's'); //line 40 error
typedef vector<string>::iterator ITER;
ITER iterEnd = vss.end();
for (ITER iter = vss.begin(); iter != iterEnd; ++iter)
copy(iter->begin(), iter->end(), ostream_iterator<string>(cout, endl));
****************************************************************
main.cpp:40: error: no matching function for call to
'get_data(std::string&, int, char)'
main.cpp:46: error: no matching function for call to
'std:stream_iterator<std::basic_string<char, std::char_traits<char>,