C++ Program to copy string using 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++

Run it Now
#include<iostream>
using namespace std;

int main() {

    string first;
    string second;

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

    second = first;

    cout << "\nThe Input value is :" << first;
    cout << "\nThe Copy value is :" << second;

    return 0;
}

Output:

Enter String value :Learn C++
The Input value is :Learn C++
The Copy value is :Learn C++