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++.

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;


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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.