原程序是下边的,弄到VC6。0里面运行说有条错误,下边的代码是网络上的程序代码,是我们这个论坛转的。我实在弄不清楚错在哪。希望各位高手告诉我下。我是个没有老师自学的菜鸟,拜托大家了
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const double PRECISION = 1E-6;
const int COUNT_OF_NUMBER = 4;
const int NUMBER_TO_BE_CAL = 24;
double number[COUNT_OF_NUMBER];
string expression[COUNT_OF_NUMBER];
bool Search(int n)
{if (n == 1)
{if ( fabs(number[0] - NUMBER_TO_BE_CAL) < PRECISION )
{cout<<expression[0]<<endl;
return true;}
else
{return false;}
}
for(int i=0;i<n;i++)
{for(int j=i+1;j<n;j++)
{double a, b;
string expa, expb;
a = number;
b = number[j];
number[j] = number[n - 1];
expa = expression;
expb = expression[j];
expression[j] = expression[n - 1];
expression = ‘(‘ + expa + ‘+’ + expb + ‘)’;
number = a + b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘-’ + expb + ‘)’;
number = a - b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expb + ‘-’ + expa + ‘)’;
number = b - a;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘*’ + expb + ‘)’;
number = a * b;
if ( Search(n - 1) ) return true;
if (b != 0)
{expression = ‘(‘ + expa + ‘/’ + expb + ‘)’;
number = a / b;
if ( Search(n - 1) ) return true;}
if (a != 0)
{expression = ‘(‘ + expb + ‘/’ + expa + ‘)’;
number = b / a;
if ( Search(n - 1) ) return true;}
number = a;
number[j] = b;
expression = expa;
expression[j] = expb;}
}
return false;
}
void main()
{for(int i = 0; i < COUNT_OF_NUMBER; i++)
{char buffer[20];
int x;
cin >> x;
number = x;
itoa(x, buffer, 10);
expression = buffer;}
if ( Search(COUNT_OF_NUMBER) )
{cout << “Success.” << endl;}
else
{cout << “Fail.” << endl;}
}
#include <string>
#include <cmath>
using namespace std;
const double PRECISION = 1E-6;
const int COUNT_OF_NUMBER = 4;
const int NUMBER_TO_BE_CAL = 24;
double number[COUNT_OF_NUMBER];
string expression[COUNT_OF_NUMBER];
bool Search(int n)
{if (n == 1)
{if ( fabs(number[0] - NUMBER_TO_BE_CAL) < PRECISION )
{cout<<expression[0]<<endl;
return true;}
else
{return false;}
}
for(int i=0;i<n;i++)
{for(int j=i+1;j<n;j++)
{double a, b;
string expa, expb;
a = number;
b = number[j];
number[j] = number[n - 1];
expa = expression;
expb = expression[j];
expression[j] = expression[n - 1];
expression = ‘(‘ + expa + ‘+’ + expb + ‘)’;
number = a + b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘-’ + expb + ‘)’;
number = a - b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expb + ‘-’ + expa + ‘)’;
number = b - a;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘*’ + expb + ‘)’;
number = a * b;
if ( Search(n - 1) ) return true;
if (b != 0)
{expression = ‘(‘ + expa + ‘/’ + expb + ‘)’;
number = a / b;
if ( Search(n - 1) ) return true;}
if (a != 0)
{expression = ‘(‘ + expb + ‘/’ + expa + ‘)’;
number = b / a;
if ( Search(n - 1) ) return true;}
number = a;
number[j] = b;
expression = expa;
expression[j] = expb;}
}
return false;
}
void main()
{for(int i = 0; i < COUNT_OF_NUMBER; i++)
{char buffer[20];
int x;
cin >> x;
number = x;
itoa(x, buffer, 10);
expression = buffer;}
if ( Search(COUNT_OF_NUMBER) )
{cout << “Success.” << endl;}
else
{cout << “Fail.” << endl;}
}
运行提示如下d:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : “eh.h is only for C++!”
Error executing cl.exe.
Error executing cl.exe.
001.exe – 1 error(s), 0 warning(s)
双击红色出,弹出一段代码,而且有光标指向#error “eh.h is only for C++!”
双击红色出,弹出一段代码,而且有光标指向#error “eh.h is only for C++!”
/***
*eh.h – User include file for exception handling.
*
* Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* User include file for exception handling.
*
* [Public]
*
****/
*eh.h – User include file for exception handling.
*
* Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* User include file for exception handling.
*
* [Public]
*
****/
#if _MSC_VER > 1000
#pragma once
#endif
#pragma once
#endif
#ifndef _INC_EH
#define _INC_EH
#define _INC_EH
#if !defined(_WIN32) && !defined(_MAC)
#error ERROR: Only Mac or Win32 targets supported!
#endif
#error ERROR: Only Mac or Win32 targets supported!
#endif
#ifdef _MSC_VER
// Currently, all MS C compilers for Win32 platforms default to 8 byte
// alignment.
#pragma pack(push,8)
#endif // _MSC_VER
#ifndef __cplusplus
#error “eh.h is only for C++!”
#endif
#error “eh.h is only for C++!”
#endif
/* Define _CRTIMP */
#ifndef _CRTIMP
#ifdef _DLL
#define _CRTIMP __declspec(dllimport)
#else /* ndef _DLL */
#define _CRTIMP
#endif /* _DLL */
#endif /* _CRTIMP */
#ifdef _DLL
#define _CRTIMP __declspec(dllimport)
#else /* ndef _DLL */
#define _CRTIMP
#endif /* _DLL */
#endif /* _CRTIMP */
/* Define _CRTAPI1 (for compatibility with the NT SDK) */
#ifndef _CRTAPI1
#if _MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif
#if _MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif
typedef void (__cdecl *terminate_function)();
typedef void (__cdecl *unexpected_function)();
typedef void (__cdecl *terminate_handler)();
typedef void (__cdecl *unexpected_handler)();
typedef void (__cdecl *unexpected_function)();
typedef void (__cdecl *terminate_handler)();
typedef void (__cdecl *unexpected_handler)();
#ifndef _MAC
struct _EXCEPTION_POINTERS;
typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
#endif
struct _EXCEPTION_POINTERS;
typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
#endif
#if _MSC_VER >= 1200
_CRTIMP __declspec(noreturn) void __cdecl terminate(void);
_CRTIMP __declspec(noreturn) void __cdecl unexpected(void);
#else
_CRTIMP void __cdecl terminate(void);
_CRTIMP void __cdecl unexpected(void);
#endif
_CRTIMP __declspec(noreturn) void __cdecl terminate(void);
_CRTIMP __declspec(noreturn) void __cdecl unexpected(void);
#else
_CRTIMP void __cdecl terminate(void);
_CRTIMP void __cdecl unexpected(void);
#endif
_CRTIMP terminate_function __cdecl set_terminate(terminate_function);
_CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function);
#ifndef _MAC
_CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function);
#endif
_CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function);
#ifndef _MAC
_CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function);
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif // _MSC_VER
#pragma pack(pop)
#endif // _MSC_VER
#endif // _INC_EH
>> 本文固定链接: http://www.vcgood.com/archives/3472
#include <string>
#include <cmath>
using namespace std;
const double PRECISION = 1E-6;
const int COUNT_OF_NUMBER = 4;
const int NUMBER_TO_BE_CAL = 24;
double number[COUNT_OF_NUMBER];
string expression[COUNT_OF_NUMBER];
bool Search(int n)
{if (n == 1)
{if ( fabs(number[0] - NUMBER_TO_BE_CAL) < PRECISION )
{cout<<expression[0]<<endl;
return true;}
else
{return false;}
}
for(int i=0;i<n;i++)
{for(int j=i+1;j<n;j++)
{double a, b;
string expa, expb;
a = number;
b = number[j];
number[j] = number[n - 1];
expa = expression;
expb = expression[j];
expression[j] = expression[n - 1];
expression = ‘(‘ + expa + ‘+’ + expb + ‘)’;
number = a + b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘-’ + expb + ‘)’;
number = a - b;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expb + ‘-’ + expa + ‘)’;
number = b - a;
if ( Search(n - 1) ) return true;
expression = ‘(‘ + expa + ‘*’ + expb + ‘)’;
number = a * b;
if ( Search(n - 1) ) return true;
if (b != 0)
{expression = ‘(‘ + expa + ‘/’ + expb + ‘)’;
number = a / b;
if ( Search(n - 1) ) return true;}
if (a != 0)
{expression = ‘(‘ + expb + ‘/’ + expa + ‘)’;
number = b / a;
if ( Search(n - 1) ) return true;}
number = a;
number[j] = b;
expression = expa;
expression[j] = expb;}
}
return false;
}
void main()
{for(int i = 0; i < COUNT_OF_NUMBER; i++)
{char buffer[20];
int x;
cin >> x;
number = x;
itoa(x, buffer, 10);
expression = buffer;}
if ( Search(COUNT_OF_NUMBER) )
{cout << “Success.” << endl;}
else
{cout << “Fail.” << endl;}
}
Error executing cl.exe.
双击红色出,弹出一段代码,而且有光标指向#error “eh.h is only for C++!”
*eh.h – User include file for exception handling.
*
* Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* User include file for exception handling.
*
* [Public]
*
****/
#pragma once
#endif
#define _INC_EH
#error ERROR: Only Mac or Win32 targets supported!
#endif
// Currently, all MS C compilers for Win32 platforms default to 8 byte
// alignment.
#pragma pack(push,8)
#endif // _MSC_VER
#error “eh.h is only for C++!”
#endif
#ifdef _DLL
#define _CRTIMP __declspec(dllimport)
#else /* ndef _DLL */
#define _CRTIMP
#endif /* _DLL */
#endif /* _CRTIMP */
#if _MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif
typedef void (__cdecl *unexpected_function)();
typedef void (__cdecl *terminate_handler)();
typedef void (__cdecl *unexpected_handler)();
struct _EXCEPTION_POINTERS;
typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
#endif
_CRTIMP __declspec(noreturn) void __cdecl terminate(void);
_CRTIMP __declspec(noreturn) void __cdecl unexpected(void);
#else
_CRTIMP void __cdecl terminate(void);
_CRTIMP void __cdecl unexpected(void);
#endif
_CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function);
#ifndef _MAC
_CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function);
#endif
#pragma pack(pop)
#endif // _MSC_VER