Re: Vector of Strings: help!
Use a stringstream to do the "dirty" work for you.
Here's a minimal (and untested) example:
Code:
std::vector<std::string> Foo(const std::string& data)
{
std::vector<std::string> result;
std::istringstream converter(data);
std::string buffer;
while(converter >> buffer)
{
result.push_back(buffer);
}
return result;
}
Re: Vector of Strings: help!
Thanks. Could you please explain what exactly have you done there?
Re: Vector of Strings: help!
Quote:
Originally Posted by assaf2b
Thanks. Could you please explain what exactly have you done there?
What is it that you don't understand?
Re: Vector of Strings: help!
Everything, really. I was given this assignment in order to be accepted into a class, but I know little to nothing (as of now) regarding C++.
Re: Vector of Strings: help!
You can't run before you learn how to walk.
I suggest you pick up a (good) book and start reading ASAP if you want to get into that class.
Re: Vector of Strings: help!
Could anyone please just write, as a comment, next to each line what it's supposed to mean... as in, why is it there?
I'd highly appreciate it.
Re: Vector of Strings: help!
Why do you think you should be accepted into the class if you can't do the assignment?
Re: Vector of Strings: help!
Quote:
Originally Posted by assaf2b
Could anyone please just write, as a comment, next to each line what it's supposed to mean... as in, why is it there?
With all due respect, that is ridiculous. No one learns programming that way, no matter what programming language is being taught.
Regards,
Paul McKenzie
Re: Vector of Strings: help!
Quote:
Originally Posted by assaf2b
Thanks. Could you please explain what exactly have you done there?
Look at the documentation for istringstream and it should be fairly obvious what he has done there.
:)