C++ Program to copy string using the string class


In this program, You will learn how to copy string using string class in C++.


string str = "Hello";

Example: How to copy string using string class in C++.

#include<iostream>
using namespace std;

int main() {

    string first;
    string second;

    cout << "Enter string value:";
    getline(cin, first);

    second = first;

    cout << "Input value is:" << first;
    cout << "\nCopy value is:" << second;

    return 0;
}

Output:

Enter string value:Welcome to xiith
Input value is:Welcome to xiith
Copy value is:Welcome to xiith