Hi, I am trying to write a program that will ask the user for their name and a random input of characters. Then, it should output to the screen the random string of characters, backwards, with their name in the middle of it. I am having trouble reversing the string, i think, and I am only having the name output at the moment. Also, would it be easier to use the 'insert' string method here? Here is my code at the moment. Still working on it.
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<fstream>
usingnamespace std;
int main()
{
string name;
string random;
cout<<"Please input your name and a random string of characters, hit enter after your name"<<endl;
getline(cin, name);
getline(cin, random);
string str1(random, int(random.length()), int(random.length())/2);
string str2(random, int(random.length())/2, 0);
cout<<str1<<name<<str2;
system("pause");
return 0;
}
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<fstream>
usingnamespace std;
int main()
{
string name;
string random;
cout<<"Please input your name and a random string of characters, hit enter after your name"<<endl;
getline(cin, name);
getline(cin, random);
random.insert(int(random.length())/2, name);
cout<<random;
system("pause");
return 0;
}