I have a template class Polinom, that uses generic data types(int, float, double, class Complex(defined by me)), and I want to convert a string to Polinom using this function for reading and a constructor:
Polion.cpp
template<typename T> istream& operator>>(istream& in, Polinom<T>& P) { char line[1000]; in.getline(line, 1000); int gr = -1; T cf[100]; char* pt; pt = strtok(linie, " "); while (pt) { cf[++gr] = T(pt); pt = strtok(NULL, " "); } P = Polinom<T>(gr, cf); return in; } Complex.cpp
Complex::Complex(const char* str){ /* ... */ } Everything is fine when I use Complex data type ( Polinom a(12, 4); std::cout << a << endl;) // I defined a friend ostream function for this line; ) because I write this constructor Complex::Complex(const char* str)
The problems appears when I use primitive data types
Polinom<int> a(12, 4); because of T(const char* ) ===> int(const char*) How can I solve this? Thank you very much!
' '? Or is any whitespace appropriate for token splitting (en.cppreference.com/w/cpp/string/byte/isspace)