#include<iostream>
#include<list>
#include<cstring>
#include<cstdlib>
usingnamespace std;
list<int> BIG_NUMBERS_SUM(char x[], char y[]);
int main()
{
char x[1000000], y[1000000];
cout<<"First number: ";
cin.getline(x, 1000000);
cout<<"The second number: ";
cin.getline(y, 1000000);
BIG_NUMBERS_SUM(x,y);
return 0;
}
list<int> BIG_NUMBERS_SUM(char x[], char y[]) // functia care face toata treaba :))
{
list<int> number_1; // declararea listelor
list<int> number_2;
list<int> sum;
list<int>::iterator i1; // declararea iteratorilor
list<int>::iterator i2;
// how can I convert the char arrays to int and then to store the values in those lists?
for(i1 = number_1.begin(); i1!=number_1.end(); i1++)
cout<<*i1<<" ";
}
I want to create a program that add two big numbers (with 1 milion digits).
Well, I want to to that using lists from STL. I want to read the numbers as char arrays and then to convert the char - arrays into integers, and then to store them into those two lists.
I know that atoi() function may help me but I don't really manage how to put every digit of that number in a location of a list. atoi() doesn't work if I want to convert only a character (for instance atoi(x[i]), it works only for the entire string.
Also I tried with assign(atoi(x)) method but it must have two parameters and it doesn't help me very much.
Please excuse my english, I am in a hurry and I hope that one of you might help me.
@ Cosmin: if Vlad's first examples don't compile for you, use the "translations" that he gave.
(Otherwise, get a newer compiler that has good support for C++11.)