의 배열을 갖는 string
의 길이를 찾아 내려고 노력하고 있지만, 함수가 작동하지 않는다. strlen()
.문자열 배열의 길이를 strlen()으로 찾는다.
string s[]={"a","b","c"};
int len = strlen(s.c_str());
그것은 다음과 같은 오류 발생 :
"request for member âc_strâ in âwArrayâ, which is of non-class type"
을하지만 내가 전에 이런 string
의에서이 strlen()
기능을 사용했을 때, 그것은 잘 작동 내가 사용하고 코드는 다음과 같은 것입니다 :
fin.open("input.txt");
string tempStr;
getline(fin, tempStr,'\n');
int len = strlen(tempStr.c_str());
내가 여기에 누락 되었습니까? 나는
int size = sizeof(s)/sizeof(s[ 0 ]);
와 string s[]
의 길이를 찾을 수 있습니다 알고하지만 strlen()
왜 사용할 수 없습니다. 누군가 일어나는 일을 설명 할 수 있습니까?
string s[]={"a","b","c"}; //array of string
for(auto i:s){
int len = strlen(i.c_str()); because you need to convert one string to c type string
cout<<len<<" ";
}
배열의 길이를 얻을 :
's'는 배열이며'c_str' 함수가 없습니다. std :: vector는 옵션입니까? – billz
'std :: string'이'std :: string []'이 아니라는 사실을 놓치고 있습니다. –
@Billz 그러나 char 형식의 배열에 대해 작동합니다. ???????????/ – DeadCoder