[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStrToInt
You could also use the Boost C++ Library's lexical_cast:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStrToInt
(C++) Converting a std::string to an integer
Use the function 'atoi', meaning 'ASCII TO Integer'.int main() { const std::string myString = "123"; const int myValue = atoi(myString.c_str()); assert(myValue == 123); }
- include <string>
- include <cassert>
You could also use the Boost C++ Library's lexical_cast:
int main() { const std::string s = "1234"; const int i = boost::lexical_cast<int>(s); assert(i == 1234); }
- include <cassert>
- include <string>
- include <boost/lexical_cast.hpp>
Other code snippets
Other string-to-int conversions
- C++ Builder
- ?C++ CLX
- C++ VCL
Code links
- ::, scope operator
- #include
- assert
- ?cassert (header file)
- const
- #include
- int
- main
- return
- std
- std::string
- string
- scope operator, ::
- return
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
