相关疑难解决方法(0)

在void函数中使用exit是错误的好习惯吗?

如果无法打开文件,我在C++ void函数中使用exit.这样做是好的做法吗?

 void ReadData()
 {
      ofstream myfile ("example.txt");
      if (! myfile.is_open())
      {
            cout << "Unable to open file";
            exit(0);
      }
      else {
            myfile << "This is a line.\n";
            myfile << "This is another line.\n";
            myfile.close();
      }
 }
Run Code Online (Sandbox Code Playgroud)

c++ exit

0
推荐指数
1
解决办法
823
查看次数

标签 统计

c++ ×1

exit ×1