#include <iostream>
#include <string>
using namespace std;
string bigNumberAdd( string num1, string num2);
int main ()
{
cout<<"please enter a number between 0-20 to set the numer of the cases"<<endl;
int caseN;
while(( cin >> caseN) && (caseN < 0||caseN > 20) ){
cout<<"please enter a number between 0-20"<<endl;
}
for (int i=1; i<=caseN; ++i){
string firstNum, secondNum;
cin >> firstNum>>secondNum;
cout<< "case "<< i << ":" <<endl;
cout<< firstNum<<" + " <<secondNum <<" = " <<bigNumberAdd(firstNum, secondNum)<< endl;
}
system("pause");
return 0;
} string bigNumberAdd(string num1, string num2)
{
if(num1.size()<num2.size())
num1.swap(num2);
num2.insert(num2.begin(), (num1.size()-num2.size()), '0');
string sum(int(num1.size()), '-1');
string::size_type carry=0;
for (string::size_type i=num1.size()-1; i>=0; --i){
string::size_type he;
he=num1[i]+num2[i]-2*'0'+carry;
sum[i]=he%10;
carry=he/10;
}
if(carry =1)
sum.insert(sum.begin(), '1');
return sum;
};
为什么编译通过了调试的时候跳出错误 求指点 困扰好久了
#include <string>
using namespace std;
string bigNumberAdd( string num1, string num2);
int main ()
{
cout<<"please enter a number between 0-20 to set the numer of the cases"<<endl;
int caseN;
while(( cin >> caseN) && (caseN < 0||caseN > 20) ){
cout<<"please enter a number between 0-20"<<endl;
}
for (int i=1; i<=caseN; ++i){
string firstNum, secondNum;
cin >> firstNum>>secondNum;
cout<< "case "<< i << ":" <<endl;
cout<< firstNum<<" + " <<secondNum <<" = " <<bigNumberAdd(firstNum, secondNum)<< endl;
}
system("pause");
return 0;
} string bigNumberAdd(string num1, string num2)
{
if(num1.size()<num2.size())
num1.swap(num2);
num2.insert(num2.begin(), (num1.size()-num2.size()), '0');
string sum(int(num1.size()), '-1');
string::size_type carry=0;
for (string::size_type i=num1.size()-1; i>=0; --i){
string::size_type he;
he=num1[i]+num2[i]-2*'0'+carry;
sum[i]=he%10;
carry=he/10;
}
if(carry =1)
sum.insert(sum.begin(), '1');
return sum;
};
为什么编译通过了调试的时候跳出错误 求指点 困扰好久了