我有以下代码.
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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出.
Connect
10.172.21.121
10.109.12.122
Run Code Online (Sandbox Code Playgroud)
我需要在ip2中将10.172.21.121存储在ip1和10.109.12.122中.我怎么做
谢谢
Cub*_*bbi 25
如果您已经在使用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';
}
Run Code Online (Sandbox Code Playgroud)
如果必须将它们转换为整数,则可以在必要时使用to_bytes进行转换.
| 归档时间: |
|
| 查看次数: |
16559 次 |
| 最近记录: |