finput.h

来自「本人自己编写的用于文本编辑开发的小软件」· C头文件 代码 · 共 39 行

H
39
字号
#ifndef FINPUT_H
#define FINPUT_H
void Finput()	//从文件读入文本
{
	v.clear();
	system("cls");
	cout<<"请输入文件名,将打开以.lhs为后缀的文件:";

	string temp;

	cin>>temp;
	temp=temp+".lhs";//添加后缀
	fstream fin(temp.c_str(),ios::in);
	if(!fin)
	{
		cout<<"文件打开失败或文件不存在!"<<endl;
		system("pause");
	}
	else
	{
		fin>>LineNum;
		fin.ignore();
		for(int i=0;i<LineNum;i++)//将文件中的文本读入到内存中去
		{
			string str;
			getline(fin,str);
			Line * tp=new Line;
			tp->length=str.size();
			tp->s=str;
			v.push_back(tp);
		}
		fin.close();
		cout<<"文件"<<temp<<"打开成功!"<<endl;//打开成功提示
		system("pause");
	}
}
#endif			

⌨️ 快捷键说明

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