find()로 찾은 문자가 처음 등장하는 위치의 숫자가 int형으로 변환되는 것에 주의한다.
#include<iostream>#include<string>usingnamespace std;intmain(void){
string S ="";
cin >> S;for(int i =97; i <=122; i ++){
cout <<(int)S.find(i)<<" ";}}
참고
char형 숫자 int형으로 변환
-> (int)S.find(j)
❗ 변환하지 않고, 없는 문자를 찾으려고 할 경우 string::npos를 반환한다,
-> string::npos는 string 클래스에 static const size_type= -1 로 명시되어 있지만, string::npos의 자료형이 unsinged이기 때문에 2의 보수 개념에 의해 표현할 수 있는 최대 크기의 양수가 출력된다. https://cryptosalamander.tistory.com/11