I am using the Chrono library to calculate the execution time of my particular line of code. I am able to calculate the execution time but when I try to write that in a file I am getting various errors. The errors I am getting are:
no match for operator <<
cannot convert diffe to type const unsigned char*
Here's an instance of my code
    int main ()
{   
    ofstream plot;
    plot.open("graph.txt");
    srand((unsigned)time(0));    
        int n = 250;
        std::cout <<"The size of the array is:" << n << std::endl;
        std::cout <<"\n";
        plot << n;
        int *arr = new int (sizeof(int)*n);
        for (int i=0;i<n;i++)
        {
            int number = (rand()%1000+1);
            arr[i] = number;
        }
        std::cout << "The array provided is:" << std::endl;
        for (int i=0;i<n;i++)
        {
            std::cout << arr[i] << " ";
        }
        std::cout << "\n";
        std::cout<<"\n";
                auto start = chrono::steady_clock::now();
                Selectionsort (arr,n);
                auto end = chrono::steady_clock::now();
                auto diffe = end-start; 
                double  a = (double ) diff;
                plot << diff;
                std::cout << "The execution time for average case is:" <<
                std::cout << chrono::duration <double, milli> (diffe).count() << " ms" << std::endl;
plot << diffe; is the reason I am getting an error. What I am doing in this code is calculating the execution time for best, worst and average case and transferring the size of the array and data to a file to plot the graph. I have no experience in using the Chrono library before
Aucun commentaire:
Enregistrer un commentaire