Hello guys,
I an new to c++ and tried to do a program wherein the user enters his name and each letter in that name gets replaced by two other letters , for example a get replaced by ka , b gets replaced by zu and something like this till z.
for example the output must be like: name: ab
new name : kazu
This is the code I created but a letter can only be replaced by one letter than two
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <algorithm>
#include <iostream>
#include <string>
#include<conio.h>
usingnamespace std;
int main()
{
char name[50];
cout<<"\n Enter your first name";
cin>>name;
string s=name ;
replace( s.begin(), s.end(), 'a', 'k' );
cout << s << endl;
getch();
}
So my question is how to do this kind of program using strings
I very much doubt it's going to get any more simple than what Cubbi just wrote. It's only ten lines long!
As for ::, this references the namespace. Everything in standard C++ lives in the namespace 'std' and so you can either call things from the std namespace like this: