I want a std::istream
to be split using commas(,
) and EOL(n
) until a certain number of the mentioned delimiters are met and the result be stored inside std::vector<std::string>
type and the rest of the std::istream
be untouched.
std::vector<std::string> split_istream(std::istream &input, int num_separators) {
std::vector<std::string> split_list;
//Does the operation on input
return split_list; // split list is the std::string segments separated by the delimiters
}
std::istream& another_function(std::istream &input) {
auto vec = split_istream(input, 2); // 2 as an example
input >> y; // defined before
}
In the above example : if the input
is a,b,c
, vec
will be {a, b}
and y
as a result will be c
. also if the input
is a,b
, vec
will be {a, b}
and in this case y
will be waiting for new input.
Can this be done? and if so how?