Files
XCEngine/docs/api/core/filewriter/filewriter.md
ssdfasd 0f0ab8922a docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.

math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.

memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)

core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md

debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md

All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00

1.9 KiB
Raw Blame History

FileWriter

命名空间: XCEngine::Core

类型: class

头文件: XCEngine/Core/FileWriter.h

描述: 文件写入工具类,提供简单的文件写入操作封装。

概述

FileWriter 是一个轻量级的文件写入工具,封装了 FILE* 接口提供便捷的字符串和二进制数据写入功能。它支持追加模式和自动资源管理RAII

公共方法

方法 描述
FileWriter() 默认构造(不打开文件)
FileWriter(filePath, append) 构造并打开文件
~FileWriter() 析构函数,自动关闭文件
Open 打开文件append=true 时为追加模式
Close 关闭文件
IsOpen 检查文件是否已打开
Write 写入数据
Flush 刷新缓冲区

使用示例

#include <XCEngine/Core/FileWriter.h>
#include <XCEngine/Containers/String.h>

using namespace XCEngine::Core;

// 方式1构造时打开
FileWriter writer("output.txt", false);
if (writer.IsOpen()) {
    writer.Write("Hello, World!\n");
    writer.Write("Line 2\n");
    writer.Flush();
}

// 方式2先构造再打开
FileWriter writer2;
if (writer2.Open("log.txt")) {
    writer2.Write("Application started\n");
    writer2.Close();
}

// 追加模式
FileWriter appendWriter("log.txt", true);
if (appendWriter.IsOpen()) {
    appendWriter.Write("Another log entry\n");
    appendWriter.Flush();
}

// 使用 String 写入
Containers::String content = "Content written from String";
FileWriter writer3("data.txt");
writer3.Write(content);

相关文档