开发者

Is there an equivalent readline().split() python function in C++?

开发者 https://www.devze.com 2023-03-25 08:10 出处:网络
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

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:

  1. Does such a function exist in C++ other than the int main() function?
  2. 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(", "));
0

精彩评论

暂无评论...
验证码 换一张
取 消