您的位置:首页 > 其它

输出ip最后一个点之后的数字

2015-12-16 11:43 260 查看
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <WinSock.h>
#include <fstream>
//#pragma comment(lib,"ws2_32.lib")
using namespace std;
//bool sort(char * num,int totalNum);

void _tmain(int argc, _TCHAR* argv[])
{

string IP1="172.16.26.29";

string IP2="172.16.26.169";

string IP3="172.16.223.23";

string ss0=IP1.substr(IP1.find_last_of('.')+1,3);

string ss1=IP2.substr(IP2.find_last_of('.')+1,3);

string ss2=IP3.substr(IP3.find_last_of('.')+1,3);

string ss3=IP2.substr(IP2.find_last_of('.')+1); //当不给定第二个参数的时候,默认输出到末尾

cout<<ss0<<endl;

cout<<ss1<<endl;

cout<<ss2<<endl;

cout<<ss3<<endl;

}

输出:29

169

23

169
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: