枚举错误码结构体数组

// testerrorenum.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
enum ReturnStatus
{
	STS_ERR_FAILED                = -999,
	STS_ERR_NOT_INITIALIZED       = -998,
	STS_ERR_NOT_ENOUGH_DATA       = -996,
	STS_ERR_NULL_PTR              = -995,
	STS_ERR_INIT                  = -899,
	STS_ERR_END_OF_STREAM         = -895,
	STS_ERR_ALLOC                 = -883,
	STS_ERR_UNSUPPORTED           = -879,
	STS_ERR_INVALID_PARAMS        = -876,
	STS_ERR_FILE_OPEN             = -875,
	STS_ERR_FORMAT                = -874,
	STS_OK                        =  0
};

typedef int Status;

struct CodeStringTable
{
	int         iCode;
	const char *pString;
};

static const CodeStringTable StringOfBaseStatus[] = {
	{ STS_OK,                   "Success" },
	{ STS_ERR_FAILED,           "General failure" },
	{ STS_ERR_NOT_INITIALIZED,  "Object is not initialized" },
	{ STS_ERR_NOT_ENOUGH_DATA,  "Not enough input data" },
	{ STS_ERR_NULL_PTR,         "Unexpected NULL pointer" },
	{ STS_ERR_INIT,             "Failed to initialize object" },
	{ STS_ERR_END_OF_STREAM,    "End of stream" },
	{ STS_ERR_ALLOC,            "Failed to allocate memory" },
	{ STS_ERR_UNSUPPORTED,      "Unsupported parameters/mode" },
	{ STS_ERR_INVALID_PARAMS,   "Invalid parameters" },
	{ STS_ERR_FILE_OPEN,        "Failed to open file" },
	{ STS_ERR_FORMAT,           "Invalid format" },
};

int _tmain(int argc, _TCHAR* argv[])
{
    ReturnStatus rstatus = STS_ERR_END_OF_STREAM;

	int j = 0;
	std::string strstring = "";
	for(j = 0 ; j <= 11; j++)
	{
    if(rstatus ==StringOfBaseStatus[j].iCode)
    strstring = StringOfBaseStatus[j].pString;
	}
	std::cout<<strstring<<std::endl;
	return 0;
}

  

posted on 2019-09-23 08:55  lydstory  阅读(314)  评论(0)    收藏  举报

导航