Files
XCEngine/docs/api/core/filewriter/Open.md
ssdfasd de4086dbfe docs: Fix core module documentation discrepancies
Fixed the following issues in XCEngine Core module documentation:
- Added 'using namespace XCEngine::Core;' to all code examples that use
  Core types (Event, FileWriter, etc.) without full namespace qualification
- Added missing '#include <XCEngine/Containers/String.h>' to FileWriter
  examples that use Containers::String
- Added '#include <string>' to Flush.md example using std::to_string

Affected files:
- core/core.md: Added using directive and Containers include
- event/*.md: Added using namespace to all 8 event doc files
- filewriter/*.md: Added using namespace and proper includes to all 6 files
2026-03-19 01:04:30 +08:00

1.0 KiB

FileWriter::Open

bool Open(const char* filePath, bool append = false);

打开文件。

描述

打开指定路径的文件,准备写入。如果之前已打开文件,会先关闭。返回是否成功打开文件。

参数:

  • filePath - 要打开的文件路径
  • append - 是否以追加模式打开,默认为覆盖模式

返回: bool - 是否成功打开

复杂度: O(1)

示例:

#include <XCEngine/Core/FileWriter.h>

using namespace XCEngine::Core;

FileWriter writer;

// 打开文件(覆盖模式)
if (writer.Open("output.txt")) {
    writer.Write("Hello\n");
    writer.Close();
}

// 打开文件(追加模式)
if (writer.Open("log.txt", true)) {
    writer.Write("Another line\n");
    writer.Flush();
}

// 检查是否成功
FileWriter writer2;
if (!writer2.Open("/invalid/path/file.txt")) {
    printf("Failed to open file\n");
}

相关文档