La funzione wcsncmp () in C ++ confronta un numero specificato di caratteri larghi di due stringhe larghe di terminazione null. Il confronto viene effettuato lessicograficamente.
La funzione wcsncmp () è definita nel file di intestazione.
prototipo di wcsncmp ()
int wcsncmp (const wchar_t * lhs, const wchar_t * rhs, size_t count);
La funzione wcsncmp () accetta due argomenti: lhs, rhs e count. Confronta lessicograficamente il contenuto di lhs e rhs fino a un massimo di conteggio caratteri.
Il segno del risultato è il segno della differenza tra le prime coppie di caratteri larghi che differiscono in lhs e rhs.
Il comportamento di wcsncmp () non è definito se lhs o rhs non puntano a stringhe estese con terminazione nulla.
Parametri wcsncmp ()
- lhs: puntatore a una delle stringhe larghe terminate da null da confrontare.
- rhs: puntatore a una delle stringhe larghe terminate da null da confrontare.
- count: numero massimo di caratteri larghi da confrontare.
wcsncmp () Restituisce il valore
La funzione wcsncmp () restituisce:
- valore positivo se il primo carattere largo differente in lhs è maggiore del corrispondente carattere largo in rhs.
- valore negativo se il primo carattere largo diverso in lhs è inferiore al corrispondente carattere largo in rhs.
- 0 se il primo conteggio dei caratteri larghi di lhs e rhs è uguale.
Esempio: come funziona la funzione wcsncmp ()?
#include #include #include using namespace std; void compare(wchar_t *lhs, wchar_t *rhs, int count) ( int result; result = wcsncmp(lhs, rhs, count); if(result> 0) wcout << rhs << " precedes " << lhs << endl; else if (result < 0) wcout << lhs << " precedes " << rhs << endl; else wcout << L"First " << count << L" characters of " << lhs << L" and " << rhs <
When you run the program, the output will be:
First 4 characters of ŦēċħʼnőļŌģƔ and Ŧēċħnology are same Ŧēċħnology precedes ŦēċħʼnőļŌģƔ