Redian新闻
>
Why no output file generate? What is wrong?
avatar
Why no output file generate? What is wrong?# Programming - 葵花宝典
r*e
1
楼主最早接触洪荒小说是上初中的时候,那时候同桌和我坐在后排,他每天上课都看小
说,我去基本机不离手,手不离机的境界,有次聊着聊着就聊上小说了,那时候最火的
小说记得有西红柿的盘龙,土豆斗破苍穹,看我同桌看了一部佛本是道,换是比较好奇
的。作者是梦入神机,讲的是混沌初开,鸿钧讲道,分发圣位,鸿钧讲道,分发圣位,
除三大亲传弟子盘古、女娲、太一外,机缘不定。其中,红云让座,准提道人打鲲鹏落
位,与接引道人得到圣位,有了证道的机缘。不知何时,女娲原因不明,证得混元。又
不知道何时,准提道人、接引道人,一见菩提、一见莲花,也证得混元。至此,得圣位
机缘者,只盘古、太一尚未成道.....就是在那一刻开始,我喜欢上了洪荒小说,接连
看了几部,但也就佛本是道最经典,有喜欢洪荒小说的吗,进来聊聊吧。
avatar
e*d
2
05/12/08
I love dreams.....I mean real dreams, not day dreams or dreams that need to be fulfilled. I always feel that we, human being, don't belong to the earth. I am so convinced that it is not designed to support us. We are disasters to the earth, and so is the earth to us. We are all desperately lonely on this crowded planet. The closer we connect to each other the more lonely we have become.
But dreams connect me with an unknown world where I feel I belong. I always know dreams are my bridge
avatar
c*e
3
Why output.txt not generated? What is wrong?
#include
#include
using namespace std;
void print(int num, fstream& fout)
{ fout << num << endl; }
int main() {
fstream fout;
fout.open("output.txt");
print(2, fout);
print(3, fout);
}
avatar
S*g
4
fout.close();

【在 c**********e 的大作中提到】
: Why output.txt not generated? What is wrong?
: #include
: #include
: using namespace std;
: void print(int num, fstream& fout)
: { fout << num << endl; }
: int main() {
: fstream fout;
: fout.open("output.txt");
: print(2, fout);

avatar
t*t
5
since you used fstream, the open mode is 0 by default. you have to
explicitly say
fout.open("...", ios_base::out);
or alternatively, use
ofstream fout;
fout.open("...");
EDIT: the default open mode is in|out by default. seems it's not stated
on standard, but i guess most implementation will do that. however, if
you specify ios_base::in, and file do not exist, the open will fail anyway.

【在 c**********e 的大作中提到】
: Why output.txt not generated? What is wrong?
: #include
: #include
: using namespace std;
: void print(int num, fstream& fout)
: { fout << num << endl; }
: int main() {
: fstream fout;
: fout.open("output.txt");
: print(2, fout);

avatar
t*t
6
this is optional given fstream is auto variable and will be destructed
automatically.

【在 S*********g 的大作中提到】
: fout.close();
avatar
c*e
7
Thanks, guru. It works.

【在 t****t 的大作中提到】
: since you used fstream, the open mode is 0 by default. you have to
: explicitly say
: fout.open("...", ios_base::out);
: or alternatively, use
: ofstream fout;
: fout.open("...");
: EDIT: the default open mode is in|out by default. seems it's not stated
: on standard, but i guess most implementation will do that. however, if
: you specify ios_base::in, and file do not exist, the open will fail anyway.

avatar
P*e
8
r u sure

this is optional given fstream is auto variable and will be destructed
automatically.

【在 t****t 的大作中提到】
: this is optional given fstream is auto variable and will be destructed
: automatically.

avatar
t*t
9
go ahead and do your test if you don't believe it. or read the spec.

【在 P********e 的大作中提到】
: r u sure
:
: this is optional given fstream is auto variable and will be destructed
: automatically.

avatar
P*e
10
u r right
but, it's better to have a close
如果是c的话
没有close (fp)是有问题的

【在 t****t 的大作中提到】
: go ahead and do your test if you don't believe it. or read the spec.
avatar
t*t
11
sure it's a good habit to have a close
but for the purpose of debugging, it's optional

【在 P********e 的大作中提到】
: u r right
: but, it's better to have a close
: 如果是c的话
: 没有close (fp)是有问题的

avatar
t*t
12
btw, for C, on exit of process, close() is optional, fclose() is mandatory
file descriptors are always automatically closed on exit, but the buffer
provided by FILE* is not automatically flushed
of course, again it's a good habit to close()/fclose() whenever the fd/FILE*
is no longer needed

【在 P********e 的大作中提到】
: u r right
: but, it's better to have a close
: 如果是c的话
: 没有close (fp)是有问题的

avatar
E*V
13
en. in when the program terninated normally

【在 P********e 的大作中提到】
: r u sure
:
: this is optional given fstream is auto variable and will be destructed
: automatically.

avatar
E*V
14
ofstream is better a

【在 c**********e 的大作中提到】
: Why output.txt not generated? What is wrong?
: #include
: #include
: using namespace std;
: void print(int num, fstream& fout)
: { fout << num << endl; }
: int main() {
: fstream fout;
: fout.open("output.txt");
: print(2, fout);

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。