代码之家  ›  专栏  ›  技术社区  ›  Abhilash Muthuraj

C++运行时错误?如何解决此问题并进行检查?

  •  1
  • Abhilash Muthuraj  · 技术社区  · 16 年前
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
        int hash, opp, i, j, c = 0;
    
        //cout<<"enter hasmat army number and opponent number\n";
        while(cin>>hash>>opp)
        {
            cout<<opp-hash<<endl;
        }
    }
    

    如何验证和测试此条件?

    解释如何在Linux中检查C++中的运行时和内存,我使用GCC版本4.4.1(Ubuntu 4.4.1-4Ubuntu9)。

    1 回复  |  直到 16 年前
        1
  •  1
  •   John Zwinck    16 年前

    编译完程序后,通过使用Unix程序运行它来检查其运行时间 time :

    time ./myprogram
    

    这将打印占用了多少“真实”(人工)时间,以及占用了多少CPU(活动处理)时间。

    如果要检查程序使用的内存量,请在调试器中运行它,并在要检查内存使用情况的位置设置断点,或者只放置一个长的 sleep() 并在不使用调试器的情况下运行它。然后你可以使用像 ps top 查看程序使用了多少内存(虚拟内存、驻留内存等)。