일상 코딩
[C++/CPP] 17.05 string 대입, 교환, 덧붙이기, 삽입 본문
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
'C++ > 따배C++ 17강 String' 카테고리의 다른 글
[C++/CPP] 17.04. 문자 접근과 배열로 전환 (0) | 2021.12.16 |
---|---|
[C++/CPP] 17.03. std::string 길이와 용량, length and capacity (0) | 2021.12.16 |
[C++/CPP] 17.02 std::String 여러 생성자들과 형변환, various constructor and typecasting (0) | 2021.12.15 |