Consider the following:
The function above is part of a Template FileIO class that stores custom objects with overloaded '<<' and '>>' operators. Works perfect, all fine...
BUT, if you pass it a vector<std::string> it only reads the first word of the string (surprise surprise) because converter only reads until the first space, unless the object has an overloaded '>>' operator.
So, my question is: Is it legal / advisable to create an overloaded '>>' operator for std::string?
Sorry if the question seems daft. C+ is hobby, not a job. So the exposure is not that great.
Code:
void ReadFile(std::vector<T>& vec) {
std::string data;
std::fstream file;
file.open(m_sfileName, std::ios::in);
if(!file.fail()) {
while(std::getline(file, data)) {
T obj;
std::stringstream converter(data);
converter >> obj;
if(!converter.fail()) {
vec.push_back(obj);
}
}
file.close();
}
}
The function above is part of a Template FileIO class that stores custom objects with overloaded '<<' and '>>' operators. Works perfect, all fine...
BUT, if you pass it a vector<std::string> it only reads the first word of the string (surprise surprise) because converter only reads until the first space, unless the object has an overloaded '>>' operator.
So, my question is: Is it legal / advisable to create an overloaded '>>' operator for std::string?
Sorry if the question seems daft. C+ is hobby, not a job. So the exposure is not that great.