以只读方式打开文件

来源:百度知道 编辑:UC知道 时间:2024/06/17 06:51:50
#include <iostream.h>
#include <fstream.h>
int fun(char* str)
{
int i=0;
char ch;
fstream file;
file.open(str,ios::in);
if( file.is_open() )
{
while( !file.eof())
{
file.get(ch);
i++;
}
file.close();
}
return i;
}
void main()
{
int num;
num = fun("temp.txt");
cout<<"temp.txt Length: "<<num<<endl;
return;
}
请分析一下怎样以只读方式打开文件,关键在于对流的应用。请详细说明,谢谢!

先告诉我,这是什么东西,一大堆的。
只读方式?
很简单,在文件(非快捷方式的文件)上,点击右键,属性,下面找到“只读按钮”,点击,按应用,确定。
快捷方式的话,找到源文件,再按以上步骤运行。