Essentially, the
int main( int argc, char** argv )
does exactly that (or to a very close extent). I was wondering if I could replicate the functionality of the int main( ... )
with other functions as well. For example, say I have a
readline();
function that reads a line from a file. I would like to know how many arguments the 开发者_开发知识库line contained argc
, as well as an array to each argument that (where a space in the line represents a new argument) argv
. So I have two questions:
- Does such a function exist in C++ other than the
int main()
function? - If not, would it be difficult to write one. If the answer to this one is also no, I'd love to hear a few pointers on where to start. I'm not that experienced with C++ and I wasn't sure whether the
string
class has anything with this functionality.
Thanks!
boost::split
#include <boost/algorithm/string.hpp>
std::vector<std::string> strs;
boost::split(strs, "word1 word2 word3", boost::is_any_of(", "));
精彩评论