1

Possible en double:
Convert a String In C++ To Upper CaseC++ toupper - fonction standard?

Salut, je besoin d'une fonction portable pour convertir la chaîne en C++ en majuscules. J'utilise maintenant toupper (char); fonction. Est-ce une fonction standard? Si non, quelle est la bonne façon de le faire à travers les plates-formes? Btw, y at-il un web/wiki où je peux lister toutes les fonctions standard C++? Je vous remercie.

Répondre

3

Oui, toupper est déclaré dans l'en-tête cctype. Vous pouvez transformer une chaîne avec un algorithme:

#include <algorithm> 
#include <iostream> 
#include <string> 
#include <cctype> 

int main() 
{ 
    std::string str("hello there"); 
    std::cout << str << '\n'; 

    std::transform(str.begin(), str.end(), str.begin(), std::toupper); 
    std::cout << str << '\n'; 
} 
+0

vous aurez besoin de la résolution portée opérateur –

+0

Y at-il une recommandation quand utiliser toupper (char) et quand toupper (char, locale)? – kangcz

+0

@John: Correction./1 plus à venir / –

0

Salut dans notre projet, nous utilisons boost/algorithme/string to_upper projet de fonction pour Windows et Linux