C / C ++のstrcoll()
関数strcoll()は、ロケール固有の照合シーケンスを使用して2つの文字列を比較するために使用されます。
-
を返します- ゼロ、両方の文字列が同じ場合
- 最初の文字列が他の文字列よりも大きい場合はゼロより大きい値
- 最初の文字列が他の文字列よりも小さい場合、ゼロ未満の値。
C言語でのstrcoll()の構文は次のとおりです。
int strcoll(const char *first_string, const char *second_string);
これがC言語でのstrcoll()の例です
例
#include <stdio.h>
#include <string.h>
int main () {
const char s1[] = "Helloworld";
const char s2[] = "Blank";
char *result;
result = strcoll(s1, s2);
if(result > 0)
printf("String s1 is greater than string s2");
else if(result < 0)
printf("String s1 is less than string s2");
else
printf(" Strings are not same");
return(0);
} 出力
String s1 is greater than string s2
-
C /C++で文字列を反転します
これはC言語で文字列を逆にする例です 例 #include<stdio.h> #include<string.h> int main() { char s[50], t; int i = 0, j = 0; printf("\nEnter the string to reverse :"); gets(s); j = strlen(s) - 1; while (i < j) { &n
-
C ++で文字列をトークン化しますか?
最初の方法は、文字列ストリームを使用して、スペースで区切られた単語を読み取ることです。これは少し制限されていますが、適切なチェックを提供すれば、タスクはかなりうまくいきます。 例 #include <vector> #include <string> #include <sstream> using namespace std; int main() { string str("Hello from the dark side"); string tmp; // A string