fork(1) download
  1. #include <iostream>
  2. #include <bitset>
  3.  
  4. int main()
  5. {
  6. std::bitset<8> bits[4];
  7. std::cout << "Enter IP: ";
  8.  
  9. for (auto &bit : bits)
  10. {
  11. unsigned long n;
  12. std::cin >> n;
  13. bit = n;
  14. std::cin.ignore();
  15. }
  16.  
  17. // test
  18. std::cout << std::endl;
  19.  
  20. for (auto const &bit : bits)
  21. std::cout << bit.to_ulong() << " ";
  22. std::cout << std::endl;
  23.  
  24. for (auto const &bit : bits)
  25. std::cout << bit.to_string();
  26. std::cout << std::endl;
  27. }
Success #stdin #stdout 0s 4388KB
stdin
192.168.0.1
stdout
Enter IP: 
192 168 0 1 
11000000101010000000000000000001