数据结构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();
相关推荐
小龙报1 小时前
【优选算法】1.搜索插入位置 2.x的平方根
java·c语言·数据结构·c++·python·算法·蓝桥杯
rimydu1974art1 小时前
# OpenCheck 废标风控系统技术实现
数据结构
rannn_1113 小时前
【力扣hot100】链表专题|21、2、19、24、92、25
java·数据结构·算法·leetcode·链表·开发
Gust of wind3 小时前
数据结构基础:线性表及其存储实现
数据结构
SNAKEpc121383 小时前
OpenGL(十五)- 着色器语言GLSL
c语言·c++·线性代数·算法·矩阵·图形渲染·着色器
欧特克_Glodon3 小时前
OpenCV计算机视觉开发入门与实践<六>:OpenCV架构模块简介
c++·人工智能·opencv·计算机视觉
Rabitebla3 小时前
C++11 新特性详解(一):列表初始化、initializer_list 与右值引用
java·开发语言·数据结构·c++·算法·leetcode·list
MC皮蛋侠客4 小时前
TDengine C++ 系列(11):性能模型与调优——从测量到优化
c++·php·tdengine
zephyr054 小时前
链表实现O(n log n)时间复杂度的排序——归并排序详解
java·数据结构·算法
兔兔兔兔15 小时前
记录C++ 3
开发语言·c++