본문 바로가기
반응형

전체 글58

C++ string 주요 멤버 함수 1. 크기 & 용량 관련size() / length() → 문자열 길이capacity() → 현재 할당된 내부 버퍼 용량reserve(n) → 최소 n 문자 저장할 수 있도록 용량 확보shrink_to_fit() → 사용하지 않는 용량을 줄임empty() → 문자열이 비었는지 확인max_size() → string이 담을 수 있는 최대 크기2. 접근 관련operator[] → 인덱스로 문자 접근 (s[0])at(pos) → 범위 체크 후 문자 접근 (예외 발생 가능)front() → 첫 번째 문자back() → 마지막 문자data() → 내부 버퍼 포인터 반환c_str() → C 스타일 문자열(const char*) 반환3. 수정 관련clear() → 문자열 비움insert(pos, str) → 문자열 .. 2025. 10. 1.
C++ <iomanip> 포맷 제어 도구 란?는 이름 그대로 **I/O Manipulators (입출력 조정기)**의 약자로, iostream(cout, cin)과 함께 쓰는 포맷 제어 도구들을 모아둔 헤더입니다.입출력 시 출력 형식(format)을 세밀하게 조정할 수 있는 함수(조정자, manipulator)를 제공합니다.예: 숫자 자리수, 소수점 표현 방식, 폭(width), 채움 문자(fill), 진법 등 주요 기능 (자주 쓰는 것)1. 소수점 자리수 제어#include cout fixed → 고정 소수점 형식scientific → 과학적 표기법setprecision(n) → 소수점 이하 자리수 n2. 출력 폭 & 채움 문자 cout setw(n) → 최소 폭 지정setfill(ch) → 빈칸 채울 문자 지정3. 진법 출력 cout hex.. 2025. 10. 1.
C++ ostringstream string 버퍼를 이용한 출력 ostringstream란?헤더: 풀네임: output string streamstd::ostream(출력 스트림) 계열인데, 출력 방향이 콘솔(cout)이 아니라 std::string 버퍼라는 점이 특징이다.즉, cout처럼 문자열로 얻을 수 있음 예제#include #include #include // setprecisionusing namespace std;int main() { double pi = 3.14159; ostringstream oss; // 문자열 출력 스트림 생성 oss 주의사항to_string과 함께 소수를 변환할때 비교해서 쓸 수 있는데 to_string과 비교하면 당연히 ostringstream을 이용하면 성능적으로는 훨씬 떨어진다.. 2025. 10. 1.
C++ to_string 숫자 -> 문자열 변환 함수 to_stringstd::string to_string(int value);std::string to_string(long value);std::string to_string(long long value);std::string to_string(unsigned value);std::string to_string(unsigned long value);std::string to_string(unsigned long long value);std::string to_string(float value);std::string to_string(double value);std::string to_string(long double value); 특징정수, 실수 타입을 받아서 std::string으로 변환내부적으로 sp.. 2025. 10. 1.
반응형