Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // separa una IP utilizando la libreria boost
- //sudo apt-get install libboost-all-dev
- #include <iostream>
- #include <boost/tokenizer.hpp>
- #include <string>
- typedef struct {unsigned short p[4];}st_ip;
- int main()
- {
- size_t pos(0);
- st_ip ip;
- std::string str = "192 168.6.189";
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep("-. ");
- tokenizer tokens(str, sep);
- for (tokenizer::iterator tok_iter = tokens.begin();tok_iter != tokens.end(); ++tok_iter)
- {
- std::cout << *tok_iter << ".";
- // unsigned short k=stoi( *tok_iter);
- ip.p[pos++]=stoi( *tok_iter);
- }
- std::cout<<std::endl;
- //Test struct
- for (size_t i=0;i<sizeof(ip.p)/sizeof(*ip.p);i++){
- std::cout <<ip.p[i]<<std::endl;
- }
- std::cout << "\n";
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement