c++ - Output Discrepancy using ctime and time_t -



c++ - Output Discrepancy using ctime and time_t -

found unusual discrepancy outputting time_t through ctime while messing around chrono , durations. missing here. there more info question after code , output. searched around bit similar question, if there 1 please direct me it.

i'm running: os: windows 7 64-bit cpu: intel core i5 m 520 2.40ghz ram: 4gb ide: microsoft visual studio express 2013

edit: total source

#include <iostream> #include <chrono> #include <ctime> #include <thread> using namespace std::chrono; int main() { duration<int, std::milli> wait(5500); time_point<system_clock> timepoint_start; time_point<system_clock> timepoint_end; time_t timet_start; time_t timet_end; std::cout << "01. timepoint_start address, sizeof: " << &timepoint_start << ", " << sizeof(timepoint_start) << std::endl; std::cout << "02. timepoint_end address, sizeof: " << &timepoint_end << ", " << sizeof(timepoint_end) << std::endl; std::cout << "03. timet_start address, sizeof: " << &timet_start << ", " << sizeof(timet_start) << std::endl; std::cout << "04. timet_end address, sizeof: " << &timet_end << ", " << sizeof(timet_end) << std::endl; timepoint_start = system_clock::now(); // < = = = = set time 1st time timet_start = system_clock::to_time_t(timepoint_start); std::cout << "05. time start: " << system_clock::to_time_t(timepoint_start) << " " << std::ctime(&timet_start); std::this_thread::sleep_for(wait); timepoint_end = system_clock::now(); // < = = = = set time 2nd time timet_end = system_clock::to_time_t(timepoint_end); std::cout << "06. time end: " << system_clock::to_time_t(timepoint_end) << " " << std::ctime(&timet_end); duration<double> elapsed_seconds = timepoint_end - timepoint_start; std::cout << "07. time start: " << system_clock::to_time_t(timepoint_start) << " 0x" << &timet_start << " " << std::ctime(&timet_start) << "08. time wait: duration<int, std::milli> wait(5500);" << std::endl << "09. time end: " << system_clock::to_time_t(timepoint_end) << " 0x" << &timet_end << " " << std::ctime(&timet_end) << "10. time elapsed: " << elapsed_seconds.count() << "s" << std::endl; std::cout << "11. time end: " << system_clock::to_time_t(timepoint_end) << " 0x" << &timet_end << " " << std::ctime(&timet_end);

and here discrepancy occurs in output edit: total output

01. timepoint_start address, sizeof: 0046faa4, 8 02. timepoint_end address, sizeof: 0046fa94, 8 03. timet_start address, sizeof: 0046fa84, 8 04. timet_end address, sizeof: 0046fa74, 8 05. time start: 1402880407 sun jun 15 20:00:07 2014 06. time end: 1402880413 sun jun 15 20:00:13 2014 07. time start: 1402880407 0x0046fa84 sun jun 15 20:00:07 2014 08. time wait: duration<int, std::milli> wait(1500); 09. time end: 1402880413 0x0046fa74 sun jun 15 20:00:07 2014 10. time elapsed: 5.50932s 11. time end: 1402880413 0x0046fa74 sun jun 15 20:00:13 2014

it understanding line 6, line 9, , line 11 of output should match in regards time stamp. line 9 of output seems picking wrong reference. there syntactically wrong here?

i'm rookie, seems unusual behavior. if in wrong section please direct me right one. want know happening here.

the std::ctime() function comes c standard, believe, , in c standard, returns pointer static memory location. can store 1 value @ time. since have single humongous std::cout << ... invocation uses std::ctime() 3 times, out of luck; 1 value displayed in 3 places, not 3 different values (in general — though details depend on how calls ctime() interleaved calls << operator, depends on compiler).

the simplest way demonstrate revise code lines labelled 7, 8, 9, 10 separate statements.

the longer term prepare require little more thought.

c++ c++11 output duration ctime

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -