online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Online C++ Compiler: Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include <cstdint> //partie simulation bibliothèque externe, class Button //========================================================================== #include <random> #include <functional> #include <chrono> class Button { public: Button(int); ~Button(); int id(); bool is_pushed(); private: int id_; }; auto rnd= std::bind( std::uniform_int_distribution<>{false, true}, std::default_random_engine( std::chrono::system_clock::now().time_since_epoch().count() ) ); Button::Button(int pin) : id_{pin} {}; Button::~Button() {}; bool Button::is_pushed() {return rnd();} int Button::id() {return id_; }; //============================================================================ enum Switch : uint8_t {C1V1= 5, C1V2, C2V1, C2V2, C2V3, D3V3, }; enum Railway: uint8_t {G1D= 22, A1G, A1D, A2G, A2D, A3G, A3D, A4G, A4D, }; const uint8_t max_handled_railways_per_switch= 4; struct Railways_switch { Button button; Railway ways[max_handled_railways_per_switch]; }; Railways_switch rs_map [] { {Button{C1V1}, {G1D, A1G, A3D}}, {Button{C2V1}, {A1G, A1D, A3D, A4D}}, {Button{C2V3}, {A2D, A3G}}, }; int main() { std::cout<< "Attention, le Train passe..."<< '\n'; for (auto& rs: rs_map) { std::cout<< "bouton: "<< rs.button.id() << '\n'; if (rs.button.is_pushed()) { std::cout<< " actionnement des voies:"<< '\n'; for (const auto& way: rs.ways) if (way) std::cout<< " "<< way<< '\n'; } else {std::cout<< " inactif"<< '\n'; }; } std::cout<< "\n Relancez le programme pour simuler un nouveau passage."; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue