易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
将C字符串转换为整数
// c string to int.cpp : Defines the entry point for the console application.
//
///功能::将C字符串转换为整数
#include "stdafx.h"
#include<iostream>
#include<cstdlib> ////atoi()
#define MAX 65535
int
main(
int
argc,
char
* argv[])
{
using
namespace
std;
char
digit_string[MAX]; //保存字符"0"---"9"的数组
char
next;
int
index = 0;
cout<<"Enter an integer and press return:";
cin.get(next);
while
(next != " ")
{
if
( isdigit(next) && (index < MAX-1) ) ///丢弃不属于"0"--"9"的字符
{
digit_string[index] = next;
index++;
}
cin.get(next);
}
cout<<endl<<endl;
cout<<"String converts to the integer :";
cout<<atoi(digit_string); ///***********
cout<<endl;
return
0;
}
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图