redies&&

std::ofstream::is_open

C++98C++11

bool is_open();

Check if file is open

Returns whether the stream is currently associated to a file.

Streams can be associated to files by a successful call to member open or directly on construction, and disassociated by calling close or on destruction.

The file association of a stream is kept by its internal stream buffer:

Internally, the function calls rdbuf()->is_open()

Parameters

none

Return Value

true if a file is open and associated with this stream object.

false otherwise.

Example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

// ofstream::is_open

#include // std::cout

#include // std::ofstream

int main () {

std::ofstream ofs;

ofs.open ("test.txt");

if (ofs.is_open())

{

ofs << "lorem ipsum";

std::cout << "Output operation successfully performed\n";

ofs.close();

}

else

{

std::cout << "Error opening file";

}

return 0;

}

Edit & Run

Possible output:

Output operation successfully performed

Data races

Accesses the ofstream object.

Concurrent access to the same stream may introduce data races.

Exception safety

相关推荐
灰子学技术16 小时前
go response.Body.close()导致连接异常处理
开发语言·后端·golang
二十雨辰17 小时前
[python]-AI大模型
开发语言·人工智能·python
Yvonne爱编码17 小时前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
Re.不晚17 小时前
JAVA进阶之路——无奖问答挑战1
java·开发语言
你这个代码我看不懂17 小时前
@ConditionalOnProperty不直接使用松绑定规则
java·开发语言
pas13617 小时前
41-parse的实现原理&有限状态机
开发语言·前端·javascript
琹箐17 小时前
最大堆和最小堆 实现思路
java·开发语言·算法
Monly2118 小时前
Java:修改打包配置文件
java·开发语言
我命由我1234518 小时前
Android 广播 - 静态注册与动态注册对广播接收器实例创建的影响
android·java·开发语言·java-ee·android studio·android-studio·android runtime
island131418 小时前
CANN ops-nn 算子库深度解析:核心算子(如激活函数、归一化)的数值精度控制与内存高效实现
开发语言·人工智能·神经网络