在AXP服务器上编译时出现问题
Problems compiling on an AXP server
所以我试图在AXP服务器上编译这个c++代码,它不想编译。我试图解决的问题是背包问题,我想用一个文件来读取数据。以下是我目前拥有的代码:
#include <iostream>
#include <fstream>
using namespace std;
// A utility function that returns maximum of two integers
int max(int a, int b)
{
return (a > b) ? a : b;
}
// Returns the maximum value that can be put in a knapsack of capacity W
int knapSack(int W, int wt[], int val[], int n)
{
int i, w;
int K[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++)
{
for (w = 0; w <= W; w++)
{
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w]= max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main()
{
ifstream myFile;
myFile.open("p1.txt");
//cout << "Enter the number of items in a Knapsack:";
int n, W;
myFile >> n;
int val[n], wt[n];
//cout << "Enter the capacity of knapsack";
myFile >> W;
for (int i = 0; i < n; i++)
{
//cout << "Enter weight and value for item " << i << ":";
myFile >> wt[i];
myFile >> val[i];
}
// int val[] = { 60, 100, 120 };
// int wt[] = { 10, 20, 30 };
// int W = 50;
cout << "The highest valid value is: " << knapSack(W, wt, val, n) << endl;
return 0;
}
下面是编译后给我的错误清单:
using namespace std;
................^
%CXX-E-MISNAMNAM, name must be a namespace name
at line number 3
int K[n + 1][W + 1];
..........^
%CXX-E-EXPRNOTCONST, expression must have a constant value
at line number 16
int K[n + 1][W + 1];
.................^
%CXX-E-EXPRNOTCONST, expression must have a constant value
at line number 16
int val[n], wt[n];
............^
%CXX-E-EXPRNOTCONST, expression must have a constant value
at line number 45
int val[n], wt[n];
...................^
%CXX-E-EXPRNOTCONST, expression must have a constant value
at line number 45
%CXX-E-MISNAMNAM
由于历史原因,HP c++默认使用ansi之前的iostreams库几个平台。这个pre-ANSI iostreams库不涉及std
因此,当您编写using namespace std;
时,编译器会报错,因为它没有在您包含的头文件中提到namespace std
。
有关详细信息,请参阅http://h71000.www7.hp.com/commercial/cplus/docs/ugv_stl.html中的7.1.2节。
如果定义了__USE_STD_IOSTREAM
宏,HP c++将使用ANSIiostream库,它存在于命名空间std
中。你可以定义它使用/DEFINE=(__USE_STD_IOSTREAM)
.
%CXX-E-EXPRNOTCONST
变长数组是C99标准的一部分,但不是c++的一部分。我我不知道惠普c++已经实现了这个扩展的标准。你可能需要重写程序以避免使用它们(可能使用std::vector
代替)来实现HP c++的编译。
http://h71000.www7.hp.com/commercial/cplus/docs/ugv_contents.html包含批号
相关文章:
- 编译包含字符串的代码时遇到问题
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 如何在 Mac 上正确编译C++,当它在 Linux 上编译没有问题时?
- Rextester 语言编译C++问题
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 编译 llvm 插件时出现问题:llvm/Config/llvm-config.h:没有这样的文件或目录
- C++ 多级虚拟继承编译问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- Qt Visual Studio 2015 加载项编译问题
- 构造函数和 G++ 编译配方的问题
- 解析问题 - 预期的非限定 ID - #include <array> 编译错误
- libssh 问题编译问题未定义的错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- Visual Studio 2017问题编译了C 代码,而该代码则在Linux中编译
- 这个C++代码有什么问题?编译错误:调用“测试::测试(测试)”没有匹配函数
- 试图编译基本Boost PropertyTree示例时出现问题-编译错误.该怎么做
- 如何解决***缺少分隔符的问题.编译QT(或支持库)时