问题描述
我想要的是一个简单的函数,它接受一个int,并返回一个char *
所以我试过
char * itoa(int i)
{
char buff [35];
返回_itoa(i, buff,10);
}
但是所有这些都是乱七八糟的。
i不明白为什么它'必须传入一个c字符串,
使用一个函数来修改它,然后打印它。当我想要做一些像
printf("%s",itoa(my_int));
的时候,它会让我感到非常恼火
但是noo ......!相反,我必须这样做
char my_string [32];
itoa(my_int,my_string,10);
printf( %s,my_string);
等等。
无论如何......我确定那里有解决方案。有没有人知道呢?
all i want is a simple function that takes an int, and returns a char*
so i tried
char * itoa(int i)
{
char buff[35];
return _itoa(i,buff,10);
}
but all it spits out is jibberish.
i don''t understand why it''s so necessary to have to pass in a c-string,
use a function to modify it, and then print it. it makes it highly
irritating when i want to do something like
printf("%s", itoa(my_int));
but noo...! instead i have to do
char my_string[32];
itoa(my_int,my_string,10);
printf("%s, my_string);
blah.
anyways... i''m sure there''s a solution out there. does anyone know it?
推荐答案
C ++常见问题怎么样:
问候,
Peter Jansson
How about the C++ faq:
http://www.parashift.com/c++-faq-lit...al-issues.html
Regards,
Peter Jansson
这篇关于itoa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!