关于 itoa

oliveadmire 2008-11-16 08:35:58
#include<iostream> //预编译命令
//#include<cstdlib> //预编译命令
using namespace std;
int main()
{
char buf[5]; //定义数组
int i=0, n=0; //定义整数变量
for( i=32; i<100; i++) //计数循环
{ //循环体
n = i*i; //构造4位数n
itoa( n, buf , 10 ); //把10 进制数 n 转换为字符串放入 buf 数组
if( (buf[0]<buf[1]) && //如果buf中的
(buf[1]<buf[2]) && // 字符串从左至右
(buf[2]<buf[3]) ) // 一个比一个小
{ cout<<"肇事汽车号码为"<<n<<endl;}
} //循环体
return 0;
}

程序中用到了itoa,为什么屏蔽//#include<cstdlib> ,也能执行。使用ctype库中函数也有这样的问题。
...全文
1258 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
michealvic 2008-12-06
  • 打赏
  • 举报
回复
7楼正解……呵呵
bfhtian 2008-11-17
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yihan7h 的回复:]
标准库 <cstdlib>被包含于 <iostream>中,所以注释掉#include <cstdlib>不影响itoa函数的调用。
再比如iomanip.h也包含了iostream.h中的所有内容,如果已经#include <iomanip.h>,那么一样的道理,不比再#include iostream.h
[/Quote]
up
zhyinty 2008-11-17
  • 打赏
  • 举报
回复
iostream相当于它们的合集了
星羽 2008-11-17
  • 打赏
  • 举报
回复

vc 上

iostream 包含了 istream
istream 包含了 ostream
ostream 包含了ios
ios 包含了xlocnum
xlocnum 包含了 cstdlib

cstdlib 里面声明了 itoa

就呆在云上 2008-11-17
  • 打赏
  • 举报
回复
呵呵
应该是iostream
包含了其他的你需要的头文件的问题吧
不过我觉得这个没有必要使劲研究啦
多包含这些标准的库文件不会出问题的啊
太乙 2008-11-17
  • 打赏
  • 举报
回复
_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow
Convert an integer to a string.

char *_itoa( int value, char *string, int radix );

char *_i64toa( __int64 value, char *string, int radix );

char * _ui64toa( unsigned _int64 value, char *string, int radix );

wchar_t * _itow( int value, wchar_t *string, int radix );

wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );

wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );

Routine Required Header Compatibility
_itoa <stdlib.h> Win 95, Win NT
_i64toa <stdlib.h> Win 95, Win NT
_ui64toa <stdlib.h> Win 95, Win NT
_itow <stdlib.h> Win 95, Win NT
_i64tow <stdlib.h> Win 95, Win NT
_ui64tow <stdlib.h> Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

Each of these functions returns a pointer to string. There is no error return.

Parameters

value

Number to be converted

string

String result

radix

Base of value; must be in the range 2 – 36

Remarks

The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 bytes) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( – ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_itot _itoa _itoa _itow


Example

/* ITOA.C: This program converts integers of various
* sizes to strings in various radixes.
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;

_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );

_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );

_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}


Output

String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2


Data Conversion Routines

See Also _ltoa, _ultoa

yinghui130 2008-11-17
  • 打赏
  • 举报
回复
头文件iostream->istream->ostream->ios->streambuf->xlocnum (->代表引用了)
在xlocnum中又引用了下面5个头文件
#include <cerrno>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <xiosbase>
yihan7h 2008-11-16
  • 打赏
  • 举报
回复
标准库<cstdlib>被包含于<iostream>中,所以注释掉#include <cstdlib>不影响itoa函数的调用。
再比如iomanip.h也包含了iostream.h中的所有内容,如果已经#include <iomanip.h>,那么一样的道理,不比再#include iostream.h
wzyzb 2008-11-16
  • 打赏
  • 举报
回复
jf
jackzhhuang 2008-11-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Longinc 的回复:]
引用 2 楼 akirya 的回复:
可能会被其他头文件所包含.

UP
[/Quote]
yes
Longinc 2008-11-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 akirya 的回复:]
可能会被其他头文件所包含.
[/Quote]
UP
qqwx_1986 2008-11-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 akirya 的回复:]
可能会被其他头文件所包含.
[/Quote]
up 十之八九
  • 打赏
  • 举报
回复
可能会被其他头文件所包含.
WingForce 2008-11-16
  • 打赏
  • 举报
回复
什么编译器呢?

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧