, ; std::string, , , . <cctype> for isdigit() <cstdlib> for std::atoi, ++ 11 std::stoi, .
: 141.4123, 141, .., , int.
:
int str_check(string& holder, int& x)
{
bool all_digits = true;
if (cin >> holder) {
for(const auto& i : holder) {
if (!isdigit(i) && i != '.') {
all_digits = false;
break;
}
}
if (all_digits) {
x = atoi(holder.c_str());
return 1;
}
else
return 0;
}
}
int main()
{
int x{};
string holder{};
while (1)
{
if (str_check(holder, x))
cout << x << '\n';
}
return 0;
}