Reputation: 7198
I was given a function with following signature. I can't change it, I have to work with it.
void parse(std::istream & in);
I'm supposed to test this function, so basically call it with predefined content and check if the values were properly parsed. Therefore I need to call this function... something like parse("abcdedf....")
... but I wasn't able to to find a way how to do it.
I'm new to C++ so this may be a dumb question. As far as I understand streams, istream is something that I get when reading from a source, a file for example. So I need to turn regular string into this source but I don't know how.
Upvotes: 0
Views: 3008
Reputation: 61910
Use a string stream:
std::istringstream iss("abcdef....");
parse(iss);
Like std::ifstream
, used for reading in files, std::istringstream
derives from std::istream
, so you can upcast a std::istringstream &
to a std::istream &
to pass in.
Upvotes: 2