C++ 使用boost::algorithm::split拆分字符串

C++ 使用boost::algorithm::split拆分字符串,c++,boost,C++,Boost,我有以下代码 using namespace std; using namespace boost; int main() { SystemConnect hndl; int ip1[15],ip2[15]; string line; while (cout<<"LP>" && getline(cin,line) ) { if (line=="exit") break; if (line=="Connect 10.172.21.121

我有以下代码

using namespace std;
using namespace boost;
int main()
{  
 SystemConnect hndl;
 int ip1[15],ip2[15];
 string line;
 while (cout<<"LP>" && getline(cin,line) ) {
  if (line=="exit")
   break;
  if (line=="Connect 10.172.21.121 10.109.12.122"){
   string str;
      str="ConInit 10.172.21.121 10.109.12.122";
   vector<string> results;
   split(results,str,is_any_of(" "));
   for(vector<string>::const_iterator p=results.begin();p!=results.end();p++){
    cout<<*p<<endl;
   }
  }
 }
}
我需要在ip1中存储10.172.21.121,在ip2中存储10.109.12.122。我该怎么做


谢谢

如果您已经在使用boost,为什么不将IP地址存储在相应类的对象中呢

#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
namespace ip = boost::asio::ip;
int main()
{
    std::string str = "ConInit 10.172.21.121 10.109.12.122";
    std::vector<std::string> results;
    boost::split(results, str, boost::is_any_of(" "));
    ip::address ip1 = ip::address::from_string(results[1]);
    ip::address ip2 = ip::address::from_string(results[2]);
    std::cout << " ip1 = " << ip1 << " ip2 = " << ip2 << '\n';
}
#包括
#包括
#包括
#包括
#包括
名称空间ip=boost::asio::ip;
int main()
{
std::string str=“ConInit 10.172.21.121 10.109.12.122”;
std::矢量结果;
boost::split(结果、str、boost::是(“”)的任意值);
ip::address ip1=ip::address::from_字符串(结果[1]);
ip::address ip2=ip::address::from_字符串(结果[2]);

std::cout为什么ip1和ip2被定义为int[]?您希望它们以什么形式存储IP地址?为什么您认为需要一个15元素的int数组来存储IP地址?
#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
namespace ip = boost::asio::ip;
int main()
{
    std::string str = "ConInit 10.172.21.121 10.109.12.122";
    std::vector<std::string> results;
    boost::split(results, str, boost::is_any_of(" "));
    ip::address ip1 = ip::address::from_string(results[1]);
    ip::address ip2 = ip::address::from_string(results[2]);
    std::cout << " ip1 = " << ip1 << " ip2 = " << ip2 << '\n';
}