연산자 +는 두 개의 문자열을 함께 추가하고 값이있는 새 문자열을 생성합니다. where로는 append가 문자열을 취하여 문자열 끝에 연결합니다. 여기 만 append에 대한 자세한 해당 문자열
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
string str2="Writing ";
string str3="print 10 and then 5 more";
// used in the same order as described above:
str.append(str2); // "Writing "
str.append(str3,6,3); // "10 "
str.append("dots are cool",5); // "dots "
str.append("here: "); // "here: "
str.append(10,'.'); // ".........."
str.append(str3.begin()+8,str3.end()); // " and then 5 more"
str.append<int>(5,0x2E); // "....."
cout << str << endl;
return 0;
}
의 일부를 추가처럼 또한
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "Writing";
string str2= " a book";
str.append(str2);
cout << str << endl; // "Writing a book"
return 0;
}
는, 추가 더 많은 기능을 가지고 있습니다.
두 조각에서 해당 조각을 시도하고 'str1'과 'str2'의 내용을 비교 했습니까? – mfontanini
또한'operator +'가 암시 적으로 호출되므로, 템플릿이 있고 T 타입의 구문 분석 인수가 있으면'+'연산자를 사용하고 구체적인 데이터 유형을 위해 해당 템플릿을 전문화 할 필요가 없다고 말할 수 있습니다. 암시 적 호출이 유용 할 수있는 다른 기회가 분명히 있습니다. 암시 적 호출이 항상 제어력이 떨어질 수 있다는 것을 알고 있어야하지만 ... – xQuare