I have the following function for reading in a stream of text and chopping it into a vector of a certain type:
template<class Type>
void parse_string(std::vector<Type> &type_vector, char *string)
{
std::stringstream stream(string);
while (stream.good())
{
Type t;
stream >> t;
type_vector.push_back(t);
}
}
A parameter char *stringis a piece of text representing either floating-point numbers or strings, each of which is separated by a ' 'or '\n'.
Now my problem is that during the task, the std::vector<float> type_vectorfunction parse_stringwill be separated by both delimiters ' 'and '\n'. For example, for:
0.01 0.02 0.03 0.04
0.05 0.06 0.07 0.08
He will read '0.04'and '0.05'as separate tokens. This is what I want!
However, if a is given std::vector<std::string> type_vector, it parse_stringwill be split only by ' '. Therefore, if my text looks like this:
root_joint left_hip left_knee left_ankle
left_foot right_hip right_knee right_ankle
"left_ankleleft_foot" . , , , '\n' 'left_ankle' 'left_foot'.
?
EDIT:
char *, , :
0.01 0.02 0.03 0.040.05 0.06 0.07 0.08
root_joint left_hip left_knee left_ankleleft_foot right_hip right_knee right_ankle
, , , "\n" ...
EDIT2:
, , . , .
std::vector. getLine (std:: ifstream, std::string), , , "\n" newline.