c++文件流操作接口

起源

代码中文件写入失败,测试接口

参考博客

测试代码

//main.cpp
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    
    	
	cout << "Main start running.." << endl;

	ofstream imageOut;
	string path = "./run.log";

	imageOut.open(path, ios::out | ios::binary);
	if (!imageOut.is_open()) 
	{
    
    
		cout << "Save image data to file failed, because open file failed." << endl;
		return -1;
	}

	imageOut.write("hello world!",14);
	imageOut.close();

	return 0;
}

编译

g++ main.cpp -o main -std=c++11

猜你喜欢

转载自blog.csdn.net/qq_40904479/article/details/120993284