help please !

i want to plus two strings .
i mean if i want to take large number like this 12344566677890565432333 in string
and take another number like this 239342498343094283049
i want to plus the two numbers .
how??
The same way you do it on paper.
Are you wanting to concatenate, or are you wanting the sum of these two numbers? If the former, use

http://www.cplusplus.com/reference/string/string/operator+=/

If the latter, you'll need to cast to a numeric type, add, and then store in a numeric type. You could probably do:

int sum = str1 + str2;

Your compiler might do an implicit cast for you, but it's safer to just do an explicit cast. Makes it more readable as well
int a=5;
int b=6;
int c=a+b;
cout<<c;
Be aware that your machine's unsigned int might top out at 4,294,967,295 if it's 32 bit, or 18,446,744,073,709,551,615 if it's 64 bit. Not enough for your values.

Hence why I suggest doing it as you would on paper (i.e. add the two values on the right, if the sum is greater than ten add one to a value to the left, now move on to the next two values etc etc).

Alternatively, use a bignum library.

Last edited on
Alternatively, use a bignum library.

Or use a programming language that provides a bignum library itself.
Topic archived. No new replies allowed.