Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:31:57+00:00 2026-05-22T23:31:57+00:00

I’m testing code remotely on a Solaris machine through SSH Secure Shell using c++.

  • 0

I’m testing code remotely on a Solaris machine through SSH Secure Shell using c++. Not sure of what version anything is; Solaris, the c++/compiler, etc. (and don’t know how to find out through SSH Secure Shell)…

This 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;
  }

compiles and works fine… as you can see, it converts a string entered by the user into an int…

But when modified like so:

#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;
  }

I get the following compile errors:

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

I’ve looked for spelling errors, tried moving the location of the enum line around… I dunno what in the world is going on.

Any help with this issue would be GREATLY appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:31:58+00:00Added an answer on May 22, 2026 at 11:31 pm

    The include of cmath is defining preprocessor constants OVERFLOW as 3 and UNDERFLOW as 4. So the line declaring the enum becomes (if there are no other constants):

    enum STR_TO_INT_STATUS { SUCCESS, 3, 4, INCONVERTIBLE };
    

    which, of course is not valid syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.