Write a program that take input two strings from the user and also no of chars to copy, Now copy N char of second string in first string and print the first string.
#include <iostream>
#include <string>
using namespace std;
int main() {
string str1, str2;
int n;
cout << "Enter first string: ";
getline(cin, str1);
cout << "Enter second string: ";
getline(cin, str2);
cout << "Enter n: ";
cin >> n;
str1.replace(0, n, str2);
cout << "New string is:" << endl;
cout << str1 << endl;
}
Comments
Leave a comment