Question

In: Computer Science

c++ CHRONO CLOCK wrong format.... So right now, the code im using is using std::chrono::system_clock; std::time_t...

c++ CHRONO CLOCK wrong format....

So right now, the code im using is using std::chrono::system_clock; std::time_t tt = system_clock::to_time_t (system_clock::now()); struct std::tm * ptm = std::localtime(&tt); std::cout << "Current time: " << std::put_time(ptm,"%X") << '\n'; std::this_thread::sleep_for (std::chrono::seconds(7)); It is simple in that this is in a loop, and chrono sleep_for delays the system for however many seconds. The problem is that it is in the HH:MM:SS format when I really need seconds.milliseconds to show the system clock transaction time. How would I do this? I really just need someone to explain the code, why is it making a struct? And what should I do to change the format? Thanks!

Solutions

Expert Solution

/**********************main.cpp*****************/

#include <iostream>
#include <chrono>
#include <unistd.h>

using namespace std;


int main()
{
   //get start time
   auto start_time = chrono::steady_clock::now();
   sleep(7);//do something
   //get end time of transaction
   auto end_time = chrono::steady_clock::now();

   cout << "Transaction time in milliseconds : " << chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count()<< " ms" << endl;

   cout << "Transaction time in seconds : " << chrono::duration_cast<chrono::seconds>(end_time - start_time).count()<< " sec";

   return 0;
}

/****************output***************************/

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Im asked to edit the C++ code given to me so that the user can enter...
Im asked to edit the C++ code given to me so that the user can enter as many courses as they would like. I've already built the array to house the courses, but Im a tiny bit stuck on writing the user input to the array every time a new line Is made. Code: //CSC 211 Spring 2019 //Program Description: // // Originally From: // CSC 211 Spring 2018 // Dr. Sturm // This program... // #include<iostream> #include<string> #include<fstream> using...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating the average sightings from the Total Sightings array float calcAverage(float totalSightings[],int n) {    int i;    float sum=0.0;    for(i=0;i<n;i++)    sum=sum+totalSightings[i];    return sum/n; } int main() {    // n is no. of bird watchers    //flag , flag2 and flag3 are for validating using while loops    int n,i,flag,flag2,flag3;       //ch also helps in validating    char ch;   ...
Can someone make this code work without using template? C++ using namespace std; template < typename...
Can someone make this code work without using template? C++ using namespace std; template < typename T>    void print_array(T arr[], int size)    {        ofstream outfile;        outfile.open("/Users/android/Desktop/outfile.txt");        cout << "Printing Array: " << endl;        for (int i = 0; i < size; i++)        {            cout << arr[i] << endl;            outfile << arr[i] << endl;        }    } template < typename T>...
I have a error code, for my C++ class, using Putty include <iostream> using namespace std;...
I have a error code, for my C++ class, using Putty include <iostream> using namespace std; int main() { char answer; char grade; cout << "Are you taking a class (enter y, Y, N or N): " << endl; cin >> answer; if (answer == 'N' || 'n'); { cout << "Thanks for using the system" << endl; } else if (answer == 'Y' || 'y'); { cout << "Enter a letter grade (A, B, C, D, or F): "...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char lexeme[100]; char str[200]; char nextChar; const int LETTER = 0; const int DIGIT   = 1; const int UNKNOWN = -1; const int OPAREN = 2; const int CPAREN = 3; const int PLUS = 4; const int MINUS = 5; const int MUL = 6; const int DIV = 7; const int ID_CODE = 100; const int PLUS_CODE = 101; const int MINUS_CODE =...
C++ Code! This code was written/implemented using the "class format." How would I go about in...
C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?" #include <iostream> #include <iomanip> using namespace std; class ListNode{ public: string course_name; string course_number; string course_room; ListNode* next; ListNode(){ this->next = NULL; } ListNode(string name, string number, string room){ this->course_name = name; this->course_number = number; this->course_room = room; this->next = NULL; } }; class List{ public: ListNode* head; List(){ this->head = NULL; } void insert(ListNode* Node){ if(head==NULL){ head...
Using C++, Right down a code that calculates insuranceprice:* requires driver to enter their...
Using C++, Right down a code that calculates insurance price:* requires driver to enter their age and the amounts of accidents they have hadbased on that:*base price is $500*additional fees of $100 if driver is younger than 25*additional fees based on accidents:number of accidentsfees of accidents15021253225437555756 or moreno insurance*Use switch*if had 6 or more accidents won't be able to get insurance
please write the code in C format avoid using (<<count>>) Assume that you work for a...
please write the code in C format avoid using (<<count>>) Assume that you work for a travel agency. Write a C program that performs 7 different tasks described below for this company. The flights have the following daily departure and arrival times: hotel name cost ride cost Rose 248$ 0$ Poprock 90$ 25$ flower 128$ 20$ departure time arrival time cost 7:15 am 8:25am 231$ 8:15 am 9:25am 226$ 9:15am 10:25am 226$ 10:15am 11:25am 283$ 11:15am 12:25pm 283$ 3:15pm 4:25pm...
Embedded computer systems: Configure and code clock for Pic24e referring to the example C code given...
Embedded computer systems: Configure and code clock for Pic24e referring to the example C code given below. a) Write code on how to configure bits that uses its fast RC oscillator with PLL to run at 40MHz. Assume the RC's frequency is 7.5MHz. b) Write code on how to configure bits that uses its primary crystal (XT) with PLL to run at 40MHz. Assume the external clock is a crystal oscillator of 8MHz. ====== Given C Code ======= #include "ConfigurationBits.h"...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat = 'y'; for (;repeat == 'y';){ char emplyeename[35]; float basic_Salary,EPF, Dearness_Allow, tax, Net_Salary , emplyee_id; cout << "Enter Basic Salary : "; cin >> basic_Salary; Dearness_Allow = 0.40 * basic_Salary; switch (01) {case 1: if (basic_Salary <= 2,20,00) EPF = 0; case 2: if (basic_Salary > 28000 && basic_Salary <= 60000) EPF = 0.08*basic_Salary; case 3: if (basic_Salary > 60000 && basic_Salary <= 200000)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT