cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
get int out of string with spaces
get int out of string with spaces
Feb 28, 2014 at 3:23pm UTC
hossii
(1)
How can I extract the number out of the string:
string my_sting =
"item code = 9"
;
I want to get the '9' out of the string and store it in a separate int variable.
I tried using sstream library and was having trouble.
Feb 28, 2014 at 3:54pm UTC
Catfish666
(666)
If you are using a C++11 compiler and the
regex
library is available:
http://www.cplusplus.com/reference/regex/
http://en.cppreference.com/w/cpp/regex
You can use the
regex
library to "extract" the number as a match, then use a C++11 function
std::stoi()
to actually convert the match to an
int
.
http://www.cplusplus.com/reference/string/stoi/
Topic archived. No new replies allowed.