我如何在这里追加而不是覆盖? (这段代码如何打开文件?)
How do I append instead of overwrite here? (and how does this code open a file?)
我正在阅读 OpenFoam (v7) (C++) 教程并遇到了 IO 的代码:
// Create a custom directory and write an output file
// Create the output path directory
fileName outputDir = mesh.time().path()/"postProcessing";
// Createe the directory
mkDir(outputDir);
// File pointer to direct the output to
autoPtr<OFstream> outputFilePtr;
// Open the file in the newly created directory
outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat");
// Write stuff
outputFilePtr() << "# This is a header" << endl;
outputFilePtr() << "0 1 2 3 4 5" << endl;
谁能帮忙解释一下这个文件是怎么打开的(我不明白outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat");
)
以及如何追加而不是覆盖?添加 std::ios::app 在这里似乎不起作用。
openfoam-v7 的构造函数是:
OFstream
(
const fileName& pathname,
streamFormat format=ASCII,
versionNumber version=currentVersion,
compressionType compression=UNCOMPRESSED,
const bool append = false
);
可以找到here
和
141 outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
142 ASCII,
143 currentVersion,
144 UNCOMPRESSED,
145 true) );
失败错误:“ASCII”未在此范围内声明,
错误:“currentVersion”未在此范围内声明,并且
错误:未在此范围内声明“UNCOMPRESSED”。
非常感谢您的帮助。
OFstream构造函数:
OFstream(
const fileName& pathname,
IOstreamOption streamOpt = IOstreamOption(),
const bool append = false
)
所以:
outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
IOstreamOption(),
true) );
编辑:对于旧版 OpenFOAM 的错误,很可能是命名空间问题:
outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
Foam::IOstream::ASCII
Foam::IOstream::currentVersion,
Foam::IOstream::UNCOMPRESSED,
true) );
我正在阅读 OpenFoam (v7) (C++) 教程并遇到了 IO 的代码:
// Create a custom directory and write an output file
// Create the output path directory
fileName outputDir = mesh.time().path()/"postProcessing";
// Createe the directory
mkDir(outputDir);
// File pointer to direct the output to
autoPtr<OFstream> outputFilePtr;
// Open the file in the newly created directory
outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat");
// Write stuff
outputFilePtr() << "# This is a header" << endl;
outputFilePtr() << "0 1 2 3 4 5" << endl;
谁能帮忙解释一下这个文件是怎么打开的(我不明白outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat");
)
以及如何追加而不是覆盖?添加 std::ios::app 在这里似乎不起作用。
openfoam-v7 的构造函数是:
OFstream
(
const fileName& pathname,
streamFormat format=ASCII,
versionNumber version=currentVersion,
compressionType compression=UNCOMPRESSED,
const bool append = false
);
可以找到here 和
141 outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
142 ASCII,
143 currentVersion,
144 UNCOMPRESSED,
145 true) );
失败错误:“ASCII”未在此范围内声明, 错误:“currentVersion”未在此范围内声明,并且 错误:未在此范围内声明“UNCOMPRESSED”。
非常感谢您的帮助。
OFstream构造函数:
OFstream(
const fileName& pathname,
IOstreamOption streamOpt = IOstreamOption(),
const bool append = false
)
所以:
outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
IOstreamOption(),
true) );
编辑:对于旧版 OpenFOAM 的错误,很可能是命名空间问题:
outputFilePtr.reset( new OFstream(outputDir/"customOutputFile.dat",
Foam::IOstream::ASCII
Foam::IOstream::currentVersion,
Foam::IOstream::UNCOMPRESSED,
true) );