//j#include <stdio.h>
//#include <stdlib.h>
#include <string>
//#include <ctype.h>//isspace 头文件
#include <iostream>
using namespace std;
long my_atoi(const char *a)
{
while(isspace((int)(unsigned char)*a))
{
++a;
}
int c;
c = (int)(unsigned char)*a++;
int sign = c;
int total=0;
while(isdigit(c))
{
total = total*10 + (c-'0');
c = (int)(unsigned char)*a++;
}
if(sign=='-')
return -total;
else
return total;
}
int main()
{
char *a="123345";
int b;
b= 0;
int num=2349535;
char n[10];
itoa(num,n,10); //int to char*
printf("%s\n",n);
char m[10];
sprintf(m,"%d",num);//int to char*
printf("%s\n",m);
string s=m;
// cout<<s<<endl;
printf("%s\n",s.c_str());//string 不是C的内置数据类型,,,,,所以一般用cout.
int k=0;
k=atoi(a);
printf("%d\n",k);
string aa=" 3456 ";
const char *p=aa.c_str();
b=my_atoi(p);
printf("%d\n",b);
char buff[10];
strcpy(buff,aa.c_str());
sscanf(buff,"%d",&b);
printf("%d\n",b);
system("pause");
return 0;
}
C++代码解析与转换技术
本文详细介绍了C++代码中字符串操作、数值转换、内存处理等关键技巧,并通过实例展示了如何实现字符串到整数的转换、整数到字符串的转换、以及C++代码的高效解析与内存操作。
726

被折叠的 条评论
为什么被折叠?



