Arrays 代码不适用于gcc,但适用于vs2010

Arrays 代码不适用于gcc,但适用于vs2010,arrays,visual-studio-2010,gcc,dynamic,Arrays,Visual Studio 2010,Gcc,Dynamic,我编写了以下实现循环的代码 *//roundrobin.cpp: #include <iostream> using namespace std; int main() { int numpros; int temp=0; cout<<"enter # of processes="; cin>>numpros; int twt=0; int* wt=new int[numpros];

我编写了以下实现循环的代码

*//roundrobin.cpp:

#include <iostream>

using namespace std;

int main()
{

    int numpros;

    int temp=0;

    cout<<"enter # of processes=";

    cin>>numpros;


    int twt=0;

    int* wt=new int[numpros];

    int* bt=new int[numpros];

    int* eqs=new int[numpros];

    int* remainder=new int[numpros];

    int max=0;

    int tbt=0;

    int nfq=0;

    int n,o,p,q,r;

    cout<<"enter burst time of each proccess"<<endl;

    for(q=0;q<numpros;q++)

        wt[q]=0;

    for(int i=0;i<numpros;i++)

    {


        cout<<"burst time "<<i<<"=";

        cin>>bt[i];

        //tbt=bt[i]+tbt;    

        }

    for(int j=0;j<numpros;j++)

    {

        cout<<"# of quantums of process "<<j<<"=";

        eqs[j]=bt[j]/4;

        remainder[j]=bt[j]%4;

        if(eqs[j]>max)

        {

            max=eqs[j];
            temp=j;
        }

        cout<<eqs[j]<<" "<<remainder[j]<<endl;

    }

    if(remainder[temp]>0)max++;

    //cout<<max<<endl;

    int tslicetime=numpros*4;

    for(int m=0;m<max;m++)

    {

        for(n=0;n<numpros;n++)

        {
            if(bt[n]>4)

            {
                bt[n]=bt[n]-4;
                for(o=0;o<numpros;o++)
                {
                    if(o!=n && bt[o]>0)
                    {
                        wt[o]+=4;
                    }

                }
            }
            else if(bt[n]<=4 )
            {

                    for(p=0;p<numpros;p++)
                {
                    if(p!=n && bt[p]>0)
                    {
                        wt[p]+=bt[n];
                    }

                }
                    bt[n]=0;
            }

            cout<<"p"<<n<<"="<<bt[n]<<"  ";
        }


    }
    cout<<endl;
    for(r=0;r<numpros;r++){


    }
    cout<<endl;
        for(r=0;r<numpros;r++){

        cout<<"waiting time "<<r<<"="<<wt[r]<<endl;
    }

}

你有
g++rr.cpp
但是你想要
g++-o rr.cpp
。您试图将可执行文件链接到自身,导致重复符号。

您是否应该运行“g++-o rr.cpp”?目前,您的命令行似乎试图将二进制输出作为源文件之一包含进来。。。。当然,您正在编译的文件是'rr.cpp',而不是'roundrobin.cpp',但我确信这是故意的/打字错误?
moni@moni-laptop:~/codes$ g++ rr rr.cpp
rr: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
rr:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
rr: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
rr:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
rr: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
rr: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
rr: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here
/tmp/ccB1Drkq.o: In function `main':
rr.cpp:(.text+0x0): multiple definition of `main'
rr:(.text+0xb4): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
rr:(.dtors+0x4): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in rr(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status