~文件流(fstream)操作出错~

liu6tot liu6tot 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
模仿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文件中,可是编译没法通过,请问我的函数是不是写得有问题,还是主函数调用有误???
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
liu6tot
C++ 语言 65,214 成员 250,514 内容