Je reçois un message d'erreur concernant enum (je pense)

Je suis en essais de code à distance sur un Solaris machine par SSH Secure Shell à l'aide de c++. Pas sûr de ce que la version est rien; Solaris, le c++/compilateur, etc. (et ne sais pas comment les trouver par le biais de SSH Secure Shell)...

Ce code:

#include <iostream>
#include <string>
#include <cstdlib>
#include <errno.h>
using std::cout;
using std::cin;
using std::string;
enum STR_TO_INT_STATUS { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
STR_TO_INT_STATUS str_to_int( int&, char const*, int );
int main()
{
int num;
string str;
STR_TO_INT_STATUS code;
cout << "\nEnter a string containing numbers: ";
cin >> str;
code = str_to_int( num, str.c_str(), 0 );
if( code == OVERFLOW || code == UNDERFLOW )
cout << "\nThe number was out of int's range\n\n";
else if( code == INCONVERTIBLE )
cout << "\nThe string contained non-number characters\n\n";
else if( code == SUCCESS )
cout << "\nThe int version of the string is: " << num << "\n\n";
}
STR_TO_INT_STATUS str_to_int( int &i, char const* s, int base )
{
char *end;
long l;
errno = 0;
l = strtol( s, &end, base );
if( ( errno == ERANGE && l == LONG_MAX ) || l > INT_MAX )
return OVERFLOW;
if( ( errno == ERANGE && l == LONG_MIN ) || l < INT_MIN )
return UNDERFLOW;
if( *s == '\0' || *end != '\0' )
return INCONVERTIBLE;
i = l;
return SUCCESS;
}

compile et fonctionne très bien... comme vous pouvez le voir, il convertit une chaîne de caractères saisie par l'utilisateur dans un int...

Mais quand il est modifié comme suit:

#include <iostream>
#include <string>
#include <cstdlib>
#include <errno.h>
#include <limits>
#include <cmath>
using std::cout;
using std::cin;
using std::string;
using std::numeric_limits;
int size_of( int ); //------------------------------------------------- :62
enum STR_TO_INT_STATUS { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
STR_TO_INT_STATUS str_to_int( int&, char const*, int ); //------------- :84
int main()
{
int num;
string str;
string dummy;
STR_TO_INT_STATUS code;
system( "clear" );
cout << "\nint's max limit: "
<< numeric_limits<int>::max()
<< "\nint's min limit: "
<< numeric_limits<int>::min()
<< "\n\nnumber of digits in the largest int: "
<< size_of( numeric_limits<int>::max() )
<< "\nnumber of digits in the smallest int: "
<< size_of( numeric_limits<int>::min() );
cout << "\nEnter a string containing numbers: ";
cin >> str;
code = str_to_int( num, str.c_str(), 0 );
if( code == OVERFLOW || code == UNDERFLOW )
cout << "\nThe number was out of int's range\n\n";
else if( code == INCONVERTIBLE )
cout << "\nThe string contained non-number characters\n\n";
else if( code == SUCCESS )
cout << "\nThe int version of the string is: " << num << "\n\n";
cout << "Press enter key to continue...";
getline( cin, dummy );
system( "clear" );
return( 0 );
}
int size_of( int num )
{
int length = 0;
num = ( int )fabs( num );
if( num == 0 )
length = 1;
else
while( num > 0 )
{
length++;
num /= 10;
}
return( length );
}
STR_TO_INT_STATUS str_to_int( int &i, char const* s, int base )
{
char *end;
long l;
errno = 0;
l = strtol( s, &end, base );
if( ( errno == ERANGE && l == LONG_MAX ) || l > INT_MAX )
return OVERFLOW;
if( ( errno == ERANGE && l == LONG_MIN ) || l < INT_MIN )
return UNDERFLOW;
if( *s == '\0' || *end != '\0' )
return INCONVERTIBLE;
i = l;
return SUCCESS;
}

- Je obtenir la suite des erreurs de compilation:

int_limits.cpp:16: error: expected identifier before numeric constant
int_limits.cpp:16: error: expected `}' before numeric constant
int_limits.cpp:16: error: expected unqualified-id before numeric constant
int_limits.cpp:16: error: expected `,' or `;' before numeric constant
int_limits.cpp:16: error: expected declaration before '}' token

J'ai regardé pour les fautes d'orthographe, essayé de déplacer l'emplacement de l'enum ligne autour de... je ne sais pas qu'est-ce qui se passe.

Toute aide avec ce problème serait GRANDEMENT apprécié!

nous la ligne de la nsa, dans votre posté code, nous ne pouvons pas voir les numéros de ligne ici...
Pouvez-vous nous montrer où la ligne 16 est?
C'est la ligne 16: enum STR_TO_INT_STATUS { la RÉUSSITE, le DÉPASSEMENT de, dépassement de capacité, INCONVERTIBLE };

OriginalL'auteur Aaron Chauvin | 2011-06-09