Programming Lang/C++
C++ Chapter 12-1 : C++의 표준과 표준 string 클래스
시데브
2023. 7. 26. 17:18
표준 string 클래스
- string 클래스는 C++ 표준 라이브러리에 정리된 클래스 중 하나로, 문자열의 처리를 목적으로 정의된 클래스이다.
- 헤더파일 <string>을 포함해야 사용할 수 있음
다음은 string 클래스의 사용 예시이다.
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string str1="I like ";
string str2="string class ";
string str3=str1+str2; //operator+의 오버로딩으로 객체간 덧셈연산
cout<<str1<<endl;
cout<<str2<<endl;
cout<<str3<<endl;
str1+=str2;
if(str1==str3)
cout<<"동일 문자열!"<<endl;
else
cout<<"동일하지 않은 문자열!"<<endl;
string str4;
cout<<"문자열 입력: ";
cin>>str4;
cout<<"입력한 문자열: "<<str4<<endl;
return 0;
}
I like
string class
I like string class
동일 문자열!
문자열 입력: good
입력한 문자열: good
출처 : 윤성우, <윤성우의 열혈 C++ 프로그래밍>, 오렌지미디어, 2010.05.12
728x90
반응형