When do you use code blocks?

后端 未结 4 1847
名媛妹妹
名媛妹妹 2020-12-21 03:08

When do you use code blocks in C/C++/C#, etc.? I know the theoretical reason behind them, but when do you use them in real programs?

EDIT: I have ju

4条回答
  •  眼角桃花
    2020-12-21 03:26

    You can get a finally like behavior in C++ by using code blocks and RAII objects.

    {
       std::fstream f(filename)
       ...
    }
    

    will release the file descriptor in the destructor no matter what causes us to leave the block.

    (Personally, I'm still trying to make a practice of this. My c roots hold a death grip on my habits...)

提交回复
热议问题