casting - Removing non-integers from a string in C++ -


There was a missing comment in one of my books about putting people in the comrades and messing up their program, but this was not what I was thinking, so I took a stud :: string and all the non-integer characters Tried to write a little algorithm to extract It compile the code but leaves it on the output. Why is nothing being assigned to newstring? If (isdigit (fstring [i])) does it correctly evaluate the address pointing to a point?

  // Take a little algorithm to take non-integers without string #certain on efficiency #lt; Iostream & gt; #include & lt; String & gt; Int main () {std :: cout & lt; & Lt; "Enter the number with non-integer characters:"; Std :: string fstring; Getline (standard :: Seine, extrusion); Std :: string newstring; Int i = 0, x = 0; While (i! = Fstring.length ()) {ifdigit (fstring [i])) {newstring [x] = fstring [i]; I ++; X ++; } And {i ++; }} Std :: cout & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; Newstring; System ("pause"); }  

Secondary question, it's probably somewhere else: how do you convert a string to an int (or a temporary point number)?

The new string length is 0, therefore the node string [x] where x = 0 is actually invalid Should use: newstring.append (1, fstring [i])

For secondary questions, see atoi (), atof (), strtol (0, strtof () function.


Comments