Answer to Question #188875 in C++ for Asad

Question #188875

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.


1
Expert's answer
2021-05-09T14:44:01-0400
#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;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS