[c++] 문자열의 특정 위치의 문자 가져오기
  1. 문자열 인덱싱: 문자열의 특정 위치에 있는 문자에 직접 접근하는 방법입니다. 문자열의 첫 번째 문자는 0으로 인덱싱됩니다.
#include <iostream>
#include <string>

int main() {
    std::string str = "Hello";
    char ch = str[2]; // 인덱스 2의 문자 'l'을 가져옴
    std::cout << ch << std::endl;
    return 0;
}
  1. substr 함수: 특정 범위의 문자열을 가져오는 함수입니다.
#include <iostream>
#include <string>

int main() {
    std::string str = "World";
    std::string sub = str.substr(1, 3); // 인덱스 1부터 3개의 문자를 가져옴
    std::cout << sub << std::endl;
    return 0;
}

위의 예제 코드를 사용하여 문자열의 특정 위치에 있는 문자를 가져올 수 있습니다.

참고 자료: