#include <iostream> 
#include <string> 
#include <cstring> 
#include "number_format.h" 

long string_to_long(std::string str) 
{ 
  if (str.empty()) 
    throw number_format(); 
  char pos = 0; 
  if (str[0] == '-') 
    ++pos; 
  if (pos == str.size()) 
    throw number_format(); 
  if (str[pos] < 48 || str[pos] > 57) 
    throw number_format(); 
  return std::strtol(str.c_str(), 0, 10); 
} 

int main() 
{ 
  std::string s; 

  try 
  { 
    std::cout << "Geben Sie eine Zahl ein: " << std::flush; 
    std::cin >> s; 
    std::cout << string_to_long(s) << std::endl; 
  } 
  catch (number_format &ex) 
  { 
    std::cerr << ex.what() << std::endl; 
  } 
} 
