Following are the C++ program to replace a character value from the input string:
Program Explanation:
- Defining header file.
- Defining the main method.
- Defining three different types of variables "str, P, and Ch" that are "string, integer, and character".
- After input value into the above variable, a character at method is declared that <em><u>takes position index value and replaced by character</u></em>.
- At the last using print method that <em><u>prints replaced string value</u></em>.
Program:
#include <iostream>//header file
#include <string>//header file
using namespace std;
int main() //main method
{
//defining variables
string str;//string
int P;//integer
char Ch;//character
cin>>str;//input string value
cin >>P;//input integer value
cin >> Ch;//input character value
str.at(P) = Ch; //uing char-at method that takes position index value and replaced by character
cout << str << endl;//print replaced string value
return 0;
}
Output:
Please find the attached file.
Learn more:
brainly.com/question/24497583