I am right now working on my C++ project for my programming class and I started wondering. What method's do you use to convert integer to string? There is so many of them, and most require at least 4 additional code lines. Which method do you prefer?
Name:
Anonymous2008-06-07 5:55
Screenshot + OCR
Name:
Anonymous2008-06-07 6:04
lexical_cast<string>(5);
Oh, shit, I HELPED HIM!!!. Whoops.
Name:
Anonymous2008-06-07 7:49
sscanf
Name:
Anonymous2008-06-07 7:49
I mean sprintf
Name:
Anonymous2008-06-07 8:40
I use wxWidget's string class, it handles this quite easily
If no external lib is allowed, output your numbers into a buffer.
Name:
Anonymous2008-06-07 9:31
itoa
That is the only light I shall shed into the matter.
Name:
Anonymous2008-06-07 10:14
man 3 strtod
Name:
Anonymous2008-06-07 10:14
ONE WORD THE FORCED CONVERSION OF THE STRINGS THREAD OVER
>>23
Do you have a problem with sh's ||||||||| too? Anyway, only the last $ is necessary. You can replace the others with . if you think $ is too noisy.
import Char
import List
int main(){
int i = 42;
char *s = INTEGERTOSTRING(i);
puts(s);
return 0;
}
$ gcc test_43.c -o test_43 -lm
test_43.c: In function `main':
test_43.c:16: error: syntax error before "do"
test_43.c:16: error: `_i' undeclared (first use in this function)
test_43.c:16: error: (Each undeclared identifier is reported only once
test_43.c:16: error: for each function it appears in.)
test_43.c: At top level:
test_43.c:16: error: syntax error before "while"
>>46
i tried to compile it.
your shitty do { ... } while 0 doesn't work if you want the macro to actually return something.
the way you wrote it is completely useless because it constructs a string and then doesn't give you any way to get at it.