The simplest way that makes error checking optional that I can think of is this:
char *endptr;
int x = strtol(str, &endptr, 0);
int error = (*endptr != '\0');
More Related Contents:
- How can I convert a std::string to int?
- C++ performance challenge: integer to std::string conversion
- Convert String containing several numbers into integers
- How to convert int to string in C++
- How to convert an instance of std::string to lower case
- Remove spaces from std::string in C++
- Convert string to variable name or variable type
- Check if a string contains a string in C++
- How do I check if a C++ string is an int?
- How I can print the wchar_t values to console?
- How can I get double quotes into a string literal?
- Find out if string ends with another string in C++
- C++ string to enum
- Efficient unsigned-to-signed cast avoiding implementation-defined behavior
- Split a string using C++11
- Case insensitive std::string.find()
- How to read cin with whitespace up until a newline character?
- C++ string::find complexity
- How to use string.substr() function?
- How to convert a char array to a string?
- write and read string to binary file C++
- How to read and write a STL C++ string?
- Split string by single spaces [duplicate]
- Press Enter to Continue
- How do I convert from LPCTSTR to std::string?
- Long Vs. Int C/C++ – What’s The Point?
- how to get hash code of a string in c++
- How to find and replace all occurrences of a substring in a string?
- strcmp or string::compare?
- How Can I avoid char input for an int variable?