使用std::ofstream生成文件路径
File Path generate using std::ofstream
以下代码正常工作
//m_outputFilePath and m_moduleName are strings
std::string moduleVerilog;
// call Gen function to update moduleVerilog
std::ofstream moduleVerilogFile(m_outputFilePath + "\" + m_moduleName + ".v");
if (moduleVerilogFile.is_open())
{
moduleVerilogFile << moduleVerilog;
moduleVerilogFile.close();
}
但如果我将moduleVerilogFile
更改为:
std::ofstream moduleVerilogFile(m_outputFilePath + "\Verilog\" + m_moduleName + ".v");
由于moduleVerilogFile.is_open()
返回false,因此不会向文件中写入任何内容我应该显式生成Verilog
目录吗?(看起来很奇怪)
如果Verilog
目录不存在,std::ofstream
将不会为您创建它——它的目的是读取和写入文件。如果目录不存在,它将无法打开文件,因此is_open
确实为false。
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 在C++中设置基于操作系统的文件路径
- Windows 非 ASCII 文件路径
- 非 ASCII 文件路径窗口
- C++和带有国家符号的文件路径(也许用 UTF8 编码)
- 如何为文件路径使用变量?
- 包括 VS Code 上的完整文件路径
- 如何使用提升获取当前文件路径?
- 如何在 c++ 中获取当前文件路径?
- 保存json文件后如何返回文件路径
- 从 C++ 中的文件路径中提取文件名
- 是否可以将文件路径传递给Qt中的setStyleSheet()
- 无法转换 .CATPart 文件.错误:输入文件路径似乎包含不支持的字符
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 提供依赖于输入的程序的文件路径
- 从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
- 如何更改变量文件名的文件路径?
- cmake:包括vs vs add_subDirectory:相对标头文件路径
- 在OSX中使用CGDisplayStream存储屏幕记录的特定文件路径
- 如何在另一个系统上启用文件路径