# include iostream # include string # include cstdio # includecstdlib # include string.husingnamespacestd; # definen 100类文件{ public : voidlodefile (conststringpath ); (; void file :3360 lo defile (conststringpath ) file * p=fopen (path.c _ str )、' rb '; if (! p ) exit(0; char str[N 1]; strcpy(str,path.c_str ) ); //printf(%s )、str ); //循环读取每行的shujuwhile(fgets ) str,n,p!=null}{coutstr'666'endl; printf('%s”,str; }printf(xx ); close(p ); }int main () { File file; file.lodefile ()/home/XL/demo/1.txt ); 打印(1111 ); 返回0; }运行结果
- virtualbox :~/demo/file $./fopen 12345 AAAA SD 66612345 AAAA SD其中的1.txt是已经创建的文件,在c中,由于没有fopen,因此path.c