How to convert string with commas to integer with C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <sstream>

int main() {
    std::string s = "32,746,190";
    
    s.erase(std::remove(s.begin(), s.end(), ','), s.end());
    
    std::stringstream ss(s);
  
    int n = 0;
    ss >> n;
  
    std::cout << n;
}



/*
run:

32746190

*/

 



answered Feb 14, 2022 by avibootz
...