Desc :
C언어에서는 문자열을 사용하기 위해 char배열을 사용하지만
C++에서는 string을 이용할 수 있다(물론 char배열도 구성할 수있긴함)
C - 두 문자열 합치는 함수 strcat()
C++ - +연산자 이용해 직관적으로 합치기 가능하다
Source Code :
#include <string>
#include <iostream>
using namespace std;
int main()
{
string my_country = "korea";
string my_job = "developer";
cout << "Country : " << my_country << endl;
cout << "Job : " << my_job << endl;
string my_info = my_country + ", " + my_job;
cout << "My Info : " << my_info << endl;
return 0;
}
Result :
'C++' 카테고리의 다른 글
[C++] 019 실수형 변수 (0) | 2021.01.24 |
---|---|
[C++] 018 정수형 변수 (0) | 2021.01.24 |
[C++] 016 문자형 변수 (0) | 2021.01.24 |
[C++] 015 스코핑룰 (0) | 2021.01.24 |
[C++] 014 #include (0) | 2021.01.24 |