Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

숨창고

[C++] string class (문자열) 본문

공부/C++

[C++] string class (문자열)

숨지기 2018. 11. 5. 20:40

C-string은 C언어에서 사용해오던 전통적인 문자열로서, '\0'으로 끝나는 문자배열을 문자열로 취급하는 방식이다.


C++의 string class는 내부적으로 문자열을 저장하기 위해서 char array를 사용하지만


모든 memory 관리, 할당, null종결은 모두 string class가 자체적으로 수행하며 이것이 string class가 사용하기 쉬운 이유이다.


vector와 비슷하게 memory를 동적으로 할당하기 때문에 string 객체의 length를 자유롭게 변경할 수 있다.


또 string class는 container class이기 때문에, 다른 container들(vector, set, maps)에서처럼


iterator를 통해 모든 char 원소들에 접근할 수 있고, 간단하게 []연산자를 사용할 수도 있다.


References

https://www.geeksforgeeks.org/c-string-class-and-its-applications/

http://yotop93.blogspot.com/2015/04/string.html


http://makerj.tistory.com/127