0
Is it possible to cast a string to a long without library's in c++, and if it is possible, how would you do it?
C++ no library string to long
6 Respuestas
+ 2
These are in C, the idea is to read each character in the string, do a bit of checking, and decide whether the string forms a valid numerical expression.
https://code.sololearn.com/cD9qu2qTd3RV/?ref=app
https://code.sololearn.com/czLw2SdUUhZX/?ref=app
+ 1
It is possible if we would go the extra mile writing a custom converter function for example.
+ 1
Thank you, could you post an example? I am pretty new to c++ and didn't found a fitting example
+ 1
Thank you, I'll check out later
+ 1
Kai
What is this `long =0;` in your code? I think you meant `long l = 0;` (forgot the <l>)
0
Hey, little update, I did it this way:
long convertToLong(string x) {
long l=0;
Int counter=1;
for(int i=x.length()-1;i>=0;i--){
l += counter * ((int)x[i] - 48);
counter *= 10;
}
return l;
}
Thanks for all.