在AXP服务器上编译时出现问题

Problems compiling on an AXP server

本文关键字:问题 编译 AXP 服务器      更新时间:2023-10-16

所以我试图在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包含批号