search

Home  >  Q&A  >  body text

c++ - About the use of GetTickCount()

Dear friends, after I use GetTickCount(), an error is output. Please ask for help. A screenshot is attached below. Many thanks!


#include<iostream>
#include<windows.h>
#include<fstream>
using namespace std;
ifstream infile("test.txt");
int main()
{
    int n,i=1,j,a[100000];
    DWORD time1,time2;
    while(!infile.eof()) infile>>a[i++];
    n=i-1;
    time1=GetTickCount();
    for(i=1;i<n;i++)
        for(j=1;j<n;j++)
            if(a[j]<a[j+1])
                swap(a[j],a[j+1]);   //冒泡排序
    time2=GetTickCount();
    cout<<time1-time2<<endl;
    return 0;
}


Sometimes the result will still be 0. When I was debugging, I saw that the penultimate step was still correct, but the final output result was wrong. . . Please help me, thank you very much

曾经蜡笔没有小新曾经蜡笔没有小新2759 days ago757

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-31 10:40:40

    Shouldn’t it be time2-time1

    reply
    0
  • Cancelreply