250x250
Notice
Recent Posts
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
관리 메뉴

일상 코딩

[C++/CPP] 17.05 string 대입, 교환, 덧붙이기, 삽입 본문

C++/따배C++ 17강 String

[C++/CPP] 17.05 string 대입, 교환, 덧붙이기, 삽입

polarcompass 2021. 12. 16. 21:41
728x90
#include<iostream>
#include<string>

using namespace std;

int main()
{
    
    {   
        string str1("one");
        string str2;

        str2 = str1;
        str2 = "two";
        str2.assign("two").append(" ").append("three").append(" ").append("four");

        cout << str2 << endl;
    }
    
    {
        string str1("one");
        string str2("two");

        cout << str1 << " " << str2 << endl;

        std::swap(str1, str2);
        cout << str1 << " " << str2 << endl;

        str1.swap(str2);
        cout << str1 << " " << str2 << endl;
    }

    {
        string str1("one");
        string str2("two");

        str1.append("three");
        str1.push_back('A');
        str1 += "three";

        cout << str1 << " " << str2 << endl;

        str1 = str2 + "four";

        cout << str1 << " " << str2 << endl;

    }

    {
        string str("aaaa");

        str.insert(2,"bbb");

        cout << str << endl;
    }


    return 0;
}
728x90