~文件流(fstream)操作出错~
模仿c++程序设计(钱能版)教材中的一个程序,向磁盘中一个文件写入程序的返回结果,但是在TC++3.0下编译出错,请看程序:
#include<iostream.h>
#include<fstream.h>
void fn(int a, int b)
{
if(b==0)
cerr <<"zero encountered. "
<<"The message cannot be redirected";
else
ofstream liu("e:\\rising\\cpp\\demo.txt");//编译程序提示
//“declaration not
//allowed here”
liu <<a/b; //提示语法错误,这个地方小弟觉得有错,可是又没有靠得
//住依据
cout <<a/b <<endl; //a is never used here
}
void main()
{
fn(20,2);
fn(20,0);
}
本来是想在程序可以整除的情况下,吧整除的结果输入到绝对路径下的demo.txt文件中,可是编译没法通过,请问我的函数是不是写得有问题,还是主函数调用有误???