Following case:
template <typename NumberType = double>
class A
{
//constructur, destructor,...
//member variable
std::vector<std::vector<NumberType> matrix_;
//member function
void read(std::ifstream fileIn)
{
std::string line, word;
unsigned int row = 0;
while (std::getline(fileIn, line))
{
std::istringstream lineStream(line);
unsigned int col = 0;
while (std::getline(lineStream, word, ','))
{
matrix_[row][col] = std::stod(word); // how to convert to NumberType?
col++;
}
row++;
}
}
};
I read matrix-like data from a csv file and want to store the entries in a container, whose type is a template type from a class. At the moment, I instantiate the class only for NumberType = double
, so I hard-coded std::stod(word)
for testing.
But how can I convert the string word
to NumberType
? NumberType can be float, double, long double,..., but not string, unsigned int, int,...