Convertir C++ variable chaîne de caractères de long

J'ai une variable:

string item;

Il est initialisé au moment de l'exécution. J'ai besoin de le convertir à la longue. Comment faire? J'ai essayé atol() et strtol() mais j'ai toujours erreur suivante pour strtol() et atol() respectivement:

cannot convert 'std::string' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)'

cannot convert 'std::string' to 'const char*' for argument '1' to 'long int atol(const char*)'
  • la chaîne a une fonction c_str qui va exposer comme un const char*
  • item.c_str() sera de retour const char* de la std::string.
InformationsquelleAutor kunal18 | 2012-08-02