vs2019,堆栈损坏(新手,不知道啥意思),代码如下
#include<iostream>#include<string>
using namespace std;
intLen(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;
int i = Len(all);
for (; i >= 0; i--)
{
a = all % 10;
all = all / 10;
}
for (int j = 0; j < i; j++)
{
cout << " " << str2];
}
}
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-48;//转换为数字;
}
Print(all);
return 0;
}
是一个运行是错误,错误如下:
Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted.
解决了
页:
[1]