数据结构9.3 - 文件基础(C++)

目录

上图源自:https://blog.csdn.net/LG1259156776/article/details/47035583

1 打开文件

法 1 法 2
ofstream file(path); ofstream file; file.open(path);
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

int main()
{
	char path[] = "./test.txt";
	//ofstream file(path); // 法1 
	ofstream file;
	file.open(path); // 法2 
	if(!file)
	{
		cout << "can not open the " << path + 2 << "!" <<endl;
		exit(0);
	}
	else
		cout << path + 2 << " has been opened!" << endl << endl;
	file.close();
	
	system("pause");
	return 0;
}

字符读写

关闭文件

cpp 复制代码
	file.close();
相关推荐
如竟没有火炬5 分钟前
接雨水22
数据结构·python·算法·leetcode·散列表
ʚ希希ɞ ྀ13 分钟前
二叉树的锯齿层序遍历
数据结构·算法
June`32 分钟前
高并发内存池如何实现
c++·tcmalloc·内存池
ComputerInBook32 分钟前
C++ 关键字 constexpr 和 consteval 之注意事项
开发语言·c++·constexpr·consteval
米啦啦.1 小时前
STL(标准模板库)
开发语言·c++·stl
咩咦1 小时前
C++学习笔记08:指针和引用的区别
c++·学习笔记·指针·引用·指针和引用
洛水水1 小时前
【力扣100题】34.二叉搜索树中第K小的元素
c++·算法·leetcode
许长安1 小时前
gRPC Keepalive 机制
c++·经验分享·笔记·rpc
tyung2 小时前
用 Go 实现一个生产级 Ring Buffer Queue:环形数组、位运算取模、批量操作全拆解
数据结构·go
wangjialelele2 小时前
Linux SystemV 消息队列 + 责任链模式:实现客户端消息处理流水线
linux·服务器·c语言·网络·c++·责任链模式