#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using std::cerr;
using std::cout;
using std::stringstream;
using std::string;
using std::for_each;
void convert(const string& a_value)
{
unsigned short i;
if (stringstream(a_value) >> i)
cout << a_value << " converted to " << i << ".\n";
else
cerr << a_value << " failed to convert.\n";
}
int main()
{
string inputs[] = { "abc", "10", "999999999999999999999", "-10", "0" };
for_each(inputs, inputs + (sizeof(inputs)/sizeof(inputs[0])), convert);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKI2luY2x1ZGUgPHN0cmluZz4KCiNpbmNsdWRlIDxzc3RyZWFtPgoKI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIHN0ZDo6Y2VycjsKCnVzaW5nIHN0ZDo6Y291dDsKCnVzaW5nIHN0ZDo6c3RyaW5nc3RyZWFtOwoKdXNpbmcgc3RkOjpzdHJpbmc7Cgp1c2luZyBzdGQ6OmZvcl9lYWNoOwoKCgp2b2lkIGNvbnZlcnQoY29uc3Qgc3RyaW5nJiBhX3ZhbHVlKQoKewoKICAgIHVuc2lnbmVkIHNob3J0IGk7CgogICAgaWYgKHN0cmluZ3N0cmVhbShhX3ZhbHVlKSA+PiBpKQoKICAgICAgICBjb3V0IDw8IGFfdmFsdWUgPDwgIiBjb252ZXJ0ZWQgdG8gIiA8PCBpIDw8ICIuXG4iOwoKICAgIGVsc2UKCiAgICAgICAgY2VyciA8PCBhX3ZhbHVlIDw8ICIgZmFpbGVkIHRvIGNvbnZlcnQuXG4iOwoKfQoKCgppbnQgbWFpbigpCgp7CgogICAgc3RyaW5nIGlucHV0c1tdID0geyAiYWJjIiwgIjEwIiwgIjk5OTk5OTk5OTk5OTk5OTk5OTk5OSIsICItMTAiLCAiMCIgfTsKCiAgICBmb3JfZWFjaChpbnB1dHMsIGlucHV0cyArIChzaXplb2YoaW5wdXRzKS9zaXplb2YoaW5wdXRzWzBdKSksIGNvbnZlcnQpOwoKICAgIHJldHVybiAwOwoKfQoK