+ 8
Why this code doesn't work on code::block but worked on visual studio?
#include <iostream> #include <thread> #include <chrono> struct Timer { std::chrono::time_point<std::chrono::steady_clock>startTime, endTime; std::chrono::duration<float> duration; Timer() { startTime = std::chrono::high_resolution_clock::now(); } ~Timer() { endTime = std::chrono::high_resolution_clock::now(); duration = endTime - startTime; float ms = duration * 1000.0f; std::cout << "It took " << ms << "ms\n"; } }; void HelloWorld() { Timer timer; for(int i = 0; i < 100; i++) std::cout << "HelloWorld!" << std::endl; } int main() { HelloWorld(); return 0; }
8 Answers
+ 5
Moritz Vogel I don't know, i was forgot. i will check out my code::block toolchain then.
+ 5
Moritz Vogel, #DARK_PROGRAMMER_✔
Sorry, for late answer and i was forgot to tell that this code have 2 error and i think my setup on codeblock are fine. Other than that i've already make a similar code that worked in code block.
2 Error Message:
no match for 'operator=' (operand types...
no match for 'operator=' (operand types...
note: no known conversion for argument 1 from..
error occurred on:
startTime = std::chrono::high_resolution_clock::now();
endTime = std::chrono::high_resolution_clock::now();
Actually there is 3 message error but i've already solved it buy putting .count() on float ms = duration.count() * 1000.0f;
https://code.sololearn.com/cOQ2FhO1wdg2/?ref=app
+ 5
Moritz Vogel, #DARK_PROGRAMMER_✔
On my other version (timing ver 2), i'm trying to make the code without classes/struct to evade the conversion on constrctor and destructor
+ 3
Cause this syntax works only on .net framework , and not on native compiler.
+ 3
Have you configured header files and path properly??
+ 3
If yes, then steady_clock may not be a valid data type or object.
+ 2
I didn't really look over your code, but maybe you didn't configure the toolchain (compiler) in code::blocks right
+ 2
#DARK_PROGRAMMER_✔ It does look like correct C++ code to me, not C#.