0
如何檢測文件是否以C++打開? 我試圖用這樣的代碼:檢測文件是否打開
int main()
{
ifstream file("file.txt");
if (/*here comes the check if file is open*/) cout<<"File open successfully"; else cout<<"File couldn't be opened. Check if the file is not used by another program or if it exists";
}
你嘗試'file.is_open()'? – 101010
你的意思是'if(file.is_open)...'嗎? – Laurcons
不,我的意思是'file.is_open()',[std :: istream :: is_open()](http://www.cplusplus.com/reference/fstream/ifstream/is_open/) – 101010