⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 流文件的打开和关闭.cpp

📁 为filename 所指定的文件名按mode 模式创建一个FILE结构数据区,并将该数据区的首地址赋值给FILE类型的指针变量fp.
💻 CPP
字号:
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<process.h>

main()
{
	FILE *fp1;
	char str[80];

	cout<<"Input a string:";
	cin.getline(str.80);

	if((fp1=fopen("d.dat","w"))==NULL)
	{
		cout<<"\nCould not open the file."<<endl;
		cout<<"Exiting program."<<endl;
		exit(1);
	}
	fputs(str,fp1);
	fputs("\n",fp1);

	fclose(fp1);

	if((fp1=fopen("d.dat","r"))==NULL)
	{
		cout<<"\nCould not open the file ."<<endl;
		cout<<"Exiting program."<<endl;
		exit(1);
	}

	char ch;
	while ((ch=fgetc(fp1)!=EOF)
		cout<<ch<<endl;
	fclose(fp1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -