[C++] 如何確認開檔讀檔時,檔案是否存在(file exist) -五種不同方式 - 郭董

[C++] 如何確認開檔讀檔時,檔案是否存在(file exist) -五種不同方式 - 郭董

瀏覽:877
日期:2024-05-23
方法一:使用is_open() 使用 is_open() 來判斷建構時開檔或是用open()開檔時,檔案與串流有無關連到 string path; cout > path; fstream fs(path.c_str(),ios::out); //fs.open(path.c_str(),ios::out); 使用open開檔 if(fs.is_open()){ cout...看更多