input and output questions about file

G

george972

hi

#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream::eek:ut|fstream::app);
string s1,s2;

if(!file) cerr<<"error"<<endl; //why the program have
//error when connecting
up "a.txt"

s1="abcd 1234\n";
file<<s1; //why don't write in a.txt?
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2<<endl;//s2 is empty

file.close();

getch();
return 0;}

the program can run without any error,but the result is:

error

s2=

the program don't create file "a.txt",How do i do?
 
L

Lew Pitcher

hi

#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream::eek:ut|fstream::app); [snip]
the program don't create file "a.txt",How do i do?

You ask the kind folks in comp.lang.c++ to help you.

(You present a problem with a C++ program; why would you expect the folk in
comp.lang.C to be of assistance? C is not C++ and C++ is not C.)

HTH
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
G

george972

Hi

You guys need to chill the **** out brothers. Replace fstream with
open/read/write if you want, its just the same.

Regards,
 
K

Kenny McCormack

First, you come here asking questions about a different language than the one
which is the subject of this group.

Then, you get shirty with the people who politely point out -- correctly --
that you're in the wrong group.

Does that sound like a recipe for getting any further assistance here?

Dear OP: You've just been threatened with a denial of service if you
don't play by their rules. This is a common tactic used frequently by
the people who control this newsgroup and want/need to maintain their
control.

Trust me, you don't want their help; they never give any usable help
anyway (*). You can tell them, for me, to FO with their rules and their
control.

(*) It is an explicit part of the design of how they keep control. They
never give any usable help - for example, they explicitly refuse to have
anything to do with anything that they think might be "homework".
 
L

Lew Pitcher

Hi

You guys need to chill the **** out brothers. Replace fstream with
open/read/write if you want, its just the same.

I'd much rather replace your fstream() with
SELECT UT-S-SYSIN ASSIGN STREAM-IN.

FD STREAM-IN RECORD IS 80, BLOCK IS 8000, LABEL RECORD IS STANDARD.
01 STREAM-DATA PIC X(80).


OPEN INPUT STREAM-IN.
READ STREAM-DATA.

but, then again, I would have coded something as much related to C as you
have. And both would be off topic here.

Yours would be on-topic in comp.lang.C++
Mine would be on-topic in comp.lang.COBOL


HTH, HAND
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
J

James Kuyper

Hi

You guys need to chill the **** out brothers. Replace fstream with
open/read/write if you want, its just the same.

open/read/write would be for comp.unix.programming. For comp.lang.c,
its' fopen(), fread(), and fwrite().

No, they are not the same. The rules governing the <iostream> portion of
the C++ standard library are connected to the rules governing the
<stdio.h> portion of the C standard library; but the relationship is
fairly complex, and many of the people who post to this newsgroup, oddly
enough, are completely unaware of what that relationship is. The people
who best understand that relationship best are mostly C++ programmers.

If you think that translating your C++ code into C is so trivial; try
converting it yourself. If, after you've completed the translation, you
still see the same problem, post it here and we'll be glad to help you
with it.
 
D

Doug Miller

Dear OP: You've just been threatened with a denial of service if you
don't play by their rules. This is a common tactic used frequently by
the people who control this newsgroup and want/need to maintain their
control.

Oh, for crying out loud. "Denial of service" my foot. Were you born this
dense, or did you train? When a question is posted to the wrong group, there's
no reasonable expectation of any "service" beyond being pointed to the *right*
group -- which is exactly what he got.
 
D

Doug Miller

Dear OP: You've just been threatened with a denial of service if you
don't play by their rules. This is a common tactic used frequently by
the people who control this newsgroup and want/need to maintain their
control.

Trust me, you don't want their help; they never give any usable help
anyway (*). You can tell them, for me, to FO with their rules and their
control.

(*) It is an explicit part of the design of how they keep control. They
never give any usable help - for example, they explicitly refuse to have
anything to do with anything that they think might be "homework".

So what is *your* reason for not providing any help? Ass.
 
K

Kenny McCormack

And you need to consider how much you're paying us before you treat us
like that.

I think that George has figured out that he's not gettin' squat from you
turds. It doesn't take much reading in this newsgroup to figure that out.
 
K

Kenny McCormack

So what is *your* reason for not providing any help? Ass.

I don't pretend to be anything other than what I am - a commentator on
the social norms of this newsgroup.
 
B

BartC

Right you are brother, substitute malloc/free if you like, it's just
the same...

You guys need to chill the f--- out brothers. Replace fstream with
open/read/write if you want, its just the same.

I wonder what's next to be just the same between C++ and C..
 
E

Eric Sosman

Hi

You guys need to chill the **** out brothers. Replace fstream with
open/read/write if you want, its just the same.

Okay, I'm chilled, and I've done as you suggest. The
compiler tells me

moron.c:1:19: iostream: No such file or directory (ENOENT)
moron.c:3:26: open/read/write: No such file or directory (ENOENT)
moron.c:5: error: parse error before "namespace"
moron.c:5: warning: type defaults to `int' in declaration of `std'
moron.c:5: error: ISO C forbids data definition with no type or storage
class
moron.c: In function `main':
moron.c:9: error: `open' undeclared (first use in this function)
moron.c:9: error: (Each undeclared identifier is reported only once
moron.c:9: error: for each function it appears in.)
moron.c:9: error: `read' undeclared (first use in this function)
moron.c:9: error: `write' undeclared (first use in this function)
moron.c:9: error: parse error before "file"
moron.c:10: error: `string' undeclared (first use in this function)
moron.c:12: error: `file' undeclared (first use in this function)
moron.c:12: error: `cerr' undeclared (first use in this function)
moron.c:12: error: `endl' undeclared (first use in this function)
moron.c:12: error: parse error before '/' token
moron.c:17: error: `s1' undeclared (first use in this function)
moron.c:17: error: parse error before '/' token
moron.c:17:23: missing terminating ' character
moron.c:17:23: warning: character constant too long for its type
moron.c:20: error: `s2' undeclared (first use in this function)
moron.c:21: error: `cout' undeclared (first use in this function)
moron.c:21: error: parse error before '/' token
moron.c:25: warning: implicit declaration of function `getch'

Compilation exited abnormally with code 1 at Mon May 25 20:11:20

.... so what should I try next?
 
L

luserXtrog

Hi

You guys need to chill the **** out brothers. Replace fstream with
open/read/write if you want, its just the same.

Regards,

Wow. Top-posted foul-mouthed overreaction to genuine
council concerning his own faux-pas. Didn't the same
thing happen the other day?

If it smells like one and gobbles little goats...
 
G

Guest

please don't top-post. Post your reply *after* what
you are replying to.

Hi

You guys need to chill the <expletive> out brothers. Replace fstream with
open/read/write if you want, its just the same.

none of fstream, open, read or write are defined by the C standard.
I'm not quite sure where to direct you to now.
 
G

george972

Ok, so why do you guys need to play the dumbass, brothers?

I write my code in C++ for power and flexibility, but in this instance
I'm interested in what's happening at the level of the underlying C
calls. Can't SOMEONE forget about C vs C++ rivalry for a second and
answer the fucking question? Why do you think I'm pissing on your
roses just because I use C++, brothers?

Regards,
 
D

Dik T. Winter

> I write my code in C++ for power and flexibility, but in this instance
> I'm interested in what's happening at the level of the underlying C
> calls.

What underlying C calls are there in:
fstream file("a.txt",fstream::in|fstream::eek:ut|fstream::app);
> Can't SOMEONE forget about C vs C++ rivalry for a second and
> answer the fucking question? Why do you think I'm pissing on your
> roses just because I use C++, brothers?

Why do you think the people in this newsgroup have any idea what the line
above actually does mean?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top