对于下面的,当std::fstream被销毁时,文件是否保证在\之后写入磁盘?
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc,char* argv[]){
{
std::fstream file{"test.txt"};
file << "when the file is actually written out?" << std::endl;
}
标题很好地解释了这一点。我有一个我截断并写入的文件(作为控制文件初始内容的测试)。然后,我想对该文件执行读/写操作。具体地说,我想写到文件的末尾,但要从头开始读。
操作步骤:
// (1) Make an initial file (truncated std::ofstream) with some contents
// (2) Close initial file stream
// (3) Re-open file with read and write permissions (std::fstream)
// (4) Set stream read pointer to begin
我想在我的日志文件中写入文件的执行日期和执行结束日期。
我不能安装任何东西,只能使用标准模块(我在linux的命令行中执行代码)。
我想要这样的东西:[TRACE] 2014-07-24 14:18:50,2014-07-24 14:18:52
我现在有这样的结果:
[TRACE] , Start date of execution : Aug 25 2014 : 10:43:02 End date of execution : Mon Aug 25 10:43:06 2014
下面是我的代码:
#include <iostream>
#include <string>
由于某些原因,以下代码无法创建新文件,即如果该文件已经存在,它将覆盖该文件,否则它将什么也不做:
#include <fstream>
int main()
{
std::fstream fs("test_out.log"); // <-- does not create a new file!
//std::fstream fs("test_out.log", std::ios_base::in | std::ios_base::out); // <-- does not create a new file!
我正在尝试制作一个具有工作高分机制的游戏,我正在使用java.io.BufferedWriter来写入一个高分文件。我没有对高分进行加密,我使用Slick2D和LWJGL进行渲染和用户输入。程序执行以下代码:
FileWriter fstream = new FileWriter("res/gabjaphou.txt");
BufferedWriter writer = new BufferedWriter(fstream);
writer.write(score); // score is an int value
writer.close(); // gotta sa
我需要创建大的测试文件-接近3 GB。因此,我尝试编写仅用于开始的字符串“1”-to检查性能和正确性。
FileWriter fstream = new FileWriter("c:/out.txt");
BufferedWriter out = new BufferedWriter(fstream,10000000);
for (int i = 0; i < 1000000000; i++) {
//out.write(Integer.toString(1));
out.write("1");
out.newLine();
}
out.clo
我有一个方法,它每隔100ms调用一次,以将一些数据保存到文件中。这个方法的输入是字节数组,它是一条消息,消息有一个类型。
private FileStream _fStream;
public void SaveData(byte[] data)
{
try
{
int type = GetTypeOfData(data);
switch (type)
{
case 0:
// do something
break;