Typing diary
string 문자열 본문
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
char ch[] = { "char" };
//string 생성자
string a; //string()
string b("name"); //string(string& str)
string c(ch); //stinrg(char* s)
string d(ch, 2); //string(char *s,int n)
cout << b << c << d; //name,char,ch를 출력하게 된다.
string *p = new string("c++"); //동적 생성
delete p;
/*
※연산자
s1 + s2 |
s1 += s2 |
s1 < s2 |s1이 사전순으로 s2 보다 앞에 오면 true
s1 > s2 |
※함수
string& replace |문자열의 pos 위치부터 n개 문자를 str 문자열로 대치
(int pos,int n, |
string& str) |
|
string substr |문자열 pos부터 n까지 문자를 새로운 string으로 생성,리턴
(int pos,int n) |
|
int length() |
int Size() |length와 동일
int capacity() |할당된 메모리 크기 리턴
|
int find |str을 발견한 처음 익덱스 리턴, 없으면 -1리턴
(string& str) |
int find |pos 위치부터 str을 검색하여 처음 인덱스 리턴, 없으면 -1리턴
(string& str, |
int pos) |
int rfind |pos 위치부터 str을 검색하여 마지막에 발견한 인덱스 리턴, 없으면 -1리턴
(string& str, |
int pos) |
|
char& at() |
void clear() |문자열 모두 삭제
*/
}
|
cs |
'C, C++' 카테고리의 다른 글
c++ 복사 생성자 (0) | 2022.08.16 |
---|---|
c++ 메모리 동적할당 초기화, 메모리 누수 (0) | 2022.08.16 |
명품 c++ programming 4강 Open Challenge (0) | 2022.08.16 |
명품 C++ programming 3강 2번문제 (0) | 2022.08.16 |
명품 c++ programming 3강 3,4,5번 (0) | 2022.08.16 |