c++ convert string with dashes to integer -



c++ convert string with dashes to integer -

using c++, if have string str ="0-7637-2129-8" how can convert 1 big integer? 763721298 strings in format. more examples: 1-2344-3457-8 = 1234434578 0-0002-0020-0 = 200200

you utilize erase-remove idiom rid of '-' characters.

#include <iostream> #include <string> #include <algorithm> int main() { std::string mystr = "0-7637-2129-8"; mystr.erase(std::remove(mystr.begin(), mystr.end(), '-'), mystr.end()); long mylong = std::atol(mystr.c_str()); // convert long std::cout << "your number " << mylong << std::endl; homecoming 0; }

working example

c++ string integer

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -