반응형
코드
# include <iostream>
# include <string>
using namespace std;
int main()
{
string s1;
cout << s1.size() << endl;
s1 = "Hello"; // Operator = (); 메모리 할당, 값을 할당
cout << s1.size() << endl;
s1 = s1 + "world"; // Operator + () 문자열 연결
cout << s1 << endl;
cout << s1.size() << endl;
string s2 = "Helloworld";
if (s1 == s2)
{
cout << "같다" << endl;
}
else
cout << "다르다" << endl;
if (s1 != s2)
cout << "다르다" << endl;
else
cout << "같다" << endl;
string path = "c:\\temp\\test\\test.txt";
cout << path << endl;
int n = path.find_last_of("\\");
string filename = path.substr(n + 1);
cout << filename << endl;
cout << path.substr(3, 5);// index 3번째에서 5개 문자를 출력
}
결과
'프로그래밍 > C++' 카테고리의 다른 글
[C++] 객체 생성과 사용 예제 (0) | 2023.02.02 |
---|---|
[C++] Heap에 할당 한 리버스(Reverse) 구현 (0) | 2023.02.02 |
[C++] 오버로딩(Overloading) 결과 출력 (0) | 2023.02.02 |
[C++] 배열의 최대값, 문자열 길이 구하기 (0) | 2023.02.02 |
[C++] 레퍼런스(Reference)로 데이터 접근 예제 (0) | 2023.02.02 |