Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';我得到一个关于枚举的错误(我想) 我通过Ssh安全壳在C++上在Solaris机器上远程测试代码。不确定什么是版本;Solaris、c++/编译器等(不知道如何通过SSH Secure Shell找到答案)_C++_Enums - Fatal编程技术网

I';我得到一个关于枚举的错误(我想) 我通过Ssh安全壳在C++上在Solaris机器上远程测试代码。不确定什么是版本;Solaris、c++/编译器等(不知道如何通过SSH Secure Shell找到答案)

I';我得到一个关于枚举的错误(我想) 我通过Ssh安全壳在C++上在Solaris机器上远程测试代码。不确定什么是版本;Solaris、c++/编译器等(不知道如何通过SSH Secure Shell找到答案),c++,enums,C++,Enums,此代码: #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

此代码:

#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;
  }
我已查找拼写错误,尝试移动枚举行的位置。。。我不知道到底发生了什么事


在此问题上的任何帮助都将不胜感激

我想是这样的:

int size_of( int );
…应该更像:

int sizeOfInt = size_of( int );
编辑

我刚刚在我的机器上编译了它,这是你的
溢出
定义#他们是邪恶的

试试这个:

enum STR_TO_INT_STATUS { STR_TO_INT_SUCCESS, STR_TO_INT_OVERFLOW, STR_TO_INT_UNDERFLOW, STR_TO_INT_INCONVERTIBLE};

cmath
的内容是将预处理器常数
OVERFLOW
定义为3,将
undflow
定义为4。因此,声明枚举的行变为(如果没有其他常量):


当然,这是无效的语法。

我猜
为一个或多个
成功
溢出
下溢
不可逆
,这会导致枚举标识符转换为“数值常量”,这反过来会导致您看到的错误

您在第一个版本中没有看到它们,因为您没有包含这些标题

检查的简单方法:尝试重命名枚举标识符

enum STR_TO_INT_STATUS { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
也许前面已经定义了像
SUCCESS
这样的枚举数。尝试使用SUCCESS\u TEST或其他方法来验证这一点

编辑
验证这一点的另一种方法是使用
-E
选项编译代码,这将显示预处理器的输出。例如:
gcc-E main.cpp

在您发布的代码中指出行号,我们在这里看不到行号……您能告诉我们第16行在哪里吗?这是第16行:枚举stru到INT_状态{成功,溢出,下溢,不可逆};这是我函数size_of()的一个协议是的,我不知道它们也被称为前向声明!令人惊叹的!!!谢谢大家的快速回复!我是新来的,不知道该核对哪个答案。。。有多种答案帮助我解决了这个问题。我可以检查所有有助于帮助所有销售代表的答案吗?
enum STR_TO_INT_STATUS { STR_TO_INT_SUCCESS, STR_TO_INT_OVERFLOW, STR_TO_INT_UNDERFLOW, STR_TO_INT_INCONVERTIBLE};
enum STR_TO_INT_STATUS { SUCCESS, 3, 4, INCONVERTIBLE };
enum STR_TO_INT_STATUS { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };