I would like to create my first template class for files manipulation. To be more specific I started with.
template <typename T>
class Foo
{
public:
Foo();
~Foo();
std::vector<Foo<T>> vec;
void parsing(T&v,T&filename);
};
template<typename T>
inline Foo<T>::Foo()
{
}
template<typename T>
inline Foo<T>::~Foo()
{
}
template<typename T>
inline void Foo<T>::parsing(T&v, T&filename){
std::fstream file;
file.open(filename, std::ios_base::in)
if (plik.good()){
typename T::value_type tmp;
while (!plik.eof()){
plik >> tmp;
v.push_back(tmp);
}
file.close();
}
}
And then I wanted to do those kind of initialization.
Foo<std::string> file;
file.parsing(vec,"file.txt");
I'm kinda new with templates so I've got following questions.
How to read/save generic types of files ? My plan was to read a file, counting words, or numbers, and pushing this into Foo-type vector. Then after manipulation on an vector I wanted to save a results of counting.
How about constructors and intitialization of variables and vectors ? Is there any specific rules that I should follow with in template class ?
Sorry for this chaotic style of question but I dont't know how to start. Thanks for all responses.