+ 12

How a character string and number string be added?

Input :absde// character string 12345// number string Output : bdvhj Help me to understand this

18th Aug 2019, 3:21 PM
Noor ❤
Noor ❤ - avatar
10 Antworten
+ 3
I think the easiest way to do this is to convert the character to its asci representarion. For example: int i = 'a' will be 97 (google 'ascii table' to find the numbering). Than you can add the integer value to the ascii value und convert it back to a character.
18th Aug 2019, 3:50 PM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 2
Tom Hammerbacher I know this How can I add a number string and character string,?? Bcoz number string is a string not integer??
18th Aug 2019, 3:43 PM
Noor ❤
Noor ❤ - avatar
24th Aug 2019, 2:38 PM
Kewal Sharma
Kewal Sharma - avatar
+ 1
This will do what you want;- #include <iostream> #include <string> using namespace std; int main() { string newstring = ""; string cs = "absde"; string ns = "12345"; for(unsigned int i = 0; i < cs.length() && i < ns.length(); i++){ newstring += cs[i] + stoi(ns.substr(i,1), nullptr); } cout << newstring; return 0; }
18th Aug 2019, 6:33 PM
rodwynnejones
rodwynnejones - avatar
+ 1
That number string can take as a character string.than we can directly concat those two strings(that will convert into asci values and add).
21st Aug 2019, 1:43 AM
Naga
Naga - avatar
+ 1
Kewal Sharma why is Python? Question was about C or C++
24th Aug 2019, 8:29 PM
UraL
24th Aug 2019, 8:31 PM
Kewal Sharma
Kewal Sharma - avatar
0
Seems like you add every character. a+1=b, b+2=d, ... So you count further in the alphabet :)
18th Aug 2019, 3:41 PM
Tom Hammerbacher
Tom Hammerbacher - avatar
0
It's better to convert the character string into number string and then add both of them...!
18th Aug 2019, 4:15 PM
Muhammed Bilal C A
Muhammed Bilal C A - avatar
0
@You did this in decrypt prog? Not so?
21st Aug 2019, 5:13 AM
UraL