|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<string>
using namespace std;
int Len(int all)
{
int i = 1;
while (i!=0)
{
i = all / 10;
if (i != 0)
{
i++;
}
return i;
}
}
void Print(int all)
{
string str2[]{ "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
int a[3];
int i = Len(all);
for (; i >= 0; i--)
{
a[i - 1] = all % 10;
all = all / 10;
}
for (int j = 0; j < i; j++)
{
cout << " " << str2[a[j]];
}
}
int main()
{
//定义一个string类对象数组来按位保存数据
string str1;
cout << "请输入一个正整数" << endl;
cin >> str1;
int all = 0;
int i = str1.size();//得到str1的长度;
for (int j = 0; j < i; j++)//从打一个数字开始加,比如1+4+5;
{
all += str1[j]-48;//转换为数字;
}
Print(all);
return 0;
}
是一个运行是错误,错误如下:
Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted.
|
|