写入位置 0x0000000000000000 时发生访问冲突。怎么改过来啊,新手求助
#include <iostream>#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std;
const int Max = 100;
class dazhengshu
{
public:
string addition(string &, string &);
void showjieguo();
private:
string outcome;
};
string dazhengshu::addition(string &str1, string &str2)
{
int x,y,mark = 0;
string str;
vector<int> num1(Max+10);
vector<int> num2(Max+10);
if(str1[0] == '-'&&str2[0] == '-')
{
mark = 1;
str1.erase(0,1);
str2.erase(0,1);
}
else if(str1[0] == '-'&&str2[0] != '-')
{
str1.erase(0,1);
outcome = addition(str2,str1);
return outcome;
}
else if(str1[0] != '-'&&str2[0] == '-')
{
str2.erase(0,1);
outcome =addition(str1,str2);
return outcome;
}
y = 0;
for(x = str1.size()-1; x >= 0; x--)
num1[y++] = str1[x]-'0';
y = 0;
for(x = str2.size()-1; x >= 0; x--)
num2[y++] = str2[x]-'0';
for(x = 0; x <= Max; x++)
{
num1[x] += num2[x];
if(num1[x]>=10)
{
num1[x] -= 10;
num1[x+1]++;
}
}
bool isBeginOutput = false;
for(x = Max; x >= 0;x--)
{
if(num1[x] != 0)
isBeginOutput = true;
if(isBeginOutput)
str += num1[x]+48;
}
if(!isBeginOutput)
str = "0";
if(mark)
str.insert(0,"-");
outcome = str;
return outcome;
}
void dazhengshu::showjieguo()
{
cout << outcome << endl;
}
int main()
{
string str1;
string str2;
dazhengshu a;
string store[10000];
char operation;
int m;
cin>>m;
for(int i=0;i<m;i++)
{
(cin>>str1>>operation>>str2);
switch(operation)
{
case '+': store[i]=a.addition(str1,str2); ;break;
case '0': exit(1);
}
}
for(int i=0;i<m;i++)
{
cout << store[i]<<endl;
}
system("pause");
return 0;
}