Skip to content

Instantly share code, notes, and snippets.

@stevenRush
Created May 1, 2013 11:29
Show Gist options
  • Save stevenRush/5494815 to your computer and use it in GitHub Desktop.
Save stevenRush/5494815 to your computer and use it in GitHub Desktop.
#include <sstream>
#include <string>
#include <iostream>
int main()
{
std::string st("192.255.a.0");
std::istringstream iss(st);
std::string st1;
int count = std::count(st.begin(), st.end(), '.');
if (count != 3)
std::cout << "Incorrect IP!\n";
//std::cout << count << std::endl;
for(int i=0; i < 4; i++)
{
std::getline(iss, st1, '.');
int number = -1;
//std::cout << st1 << std::endl;
stringstream ss(st1);
ss >> number;
std::cout << number << std::endl;
if (number < 0 || number > 255)
{
std::cout << "Incorrect IP!\n";
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment