+ 12
How a character string and number string be added?
Input :absde// character string 12345// number string Output : bdvhj Help me to understand this
11 odpowiedzi
+ 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.
+ 2
Tom Hammerbacher
I know this
How can I add a number string and character string,??
Bcoz number string is a string not integer??
+ 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;
}
+ 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).
+ 1
Kewal Sharma why is Python? Question was about C or C++
+ 1
UraL That will be easier
https://code.sololearn.com/cLlUB7keVprI/?ref=app
0
Seems like you add every character. a+1=b, b+2=d, ...
So you count further in the alphabet :)
0
It's better to convert the character string into number string and then add both of them...!
0
@You did this in decrypt prog? Not so?