Why this code doesn't work on code::block but worked on visual studio? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

1st Jan 2019, 10:21 AM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
8 Answers
+ 5
Moritz Vogel I don't know, i was forgot. i will check out my code::block toolchain then.
1st Jan 2019, 8:39 PM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
+ 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
2nd Jan 2019, 6:04 PM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
+ 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
2nd Jan 2019, 6:32 PM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
+ 3
Cause this syntax works only on .net framework , and not on native compiler.
2nd Jan 2019, 4:15 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 3
Have you configured header files and path properly??
2nd Jan 2019, 4:22 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 3
If yes, then steady_clock may not be a valid data type or object.
2nd Jan 2019, 4:23 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar
+ 2
I didn't really look over your code, but maybe you didn't configure the toolchain (compiler) in code::blocks right
1st Jan 2019, 2:42 PM
Moritz Vogel
Moritz Vogel - avatar
+ 2
#DARK_PROGRAMMER_✔ It does look like correct C++ code to me, not C#.
2nd Jan 2019, 4:19 PM
Moritz Vogel
Moritz Vogel - avatar