Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > input and output questions about file

Reply
Thread Tools

input and output questions about file

 
 
george972@mailinator.com
Guest
Posts: n/a
 
      05-25-2009
hi

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

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream: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?
 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a
 
      05-25-2009
On May 25, 2009 12:56, in comp.lang.c, http://www.velocityreviews.com/forums/(E-Mail Removed)
((E-Mail Removed)) wrote:

> hi
>
> #include<iostream>
> #include<conio.h>
> #include<fstream>
>
> using namespace std;
>
> int main()
> {
> fstream file("a.txt",fstream::in|fstream: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. ------


 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      05-25-2009
(E-Mail Removed) wrote:
> hi
>
> #include<iostream>


<snip>

You are asking about C++ so you need to ask in comp.lang.c++, this group
is for C which does not have fstream etc.
--
Flash Gordon
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      05-25-2009
(E-Mail Removed) writes:

> #include<iostream>


You are using C++ so you should post in comp.lang.c++.

<snip>
--
Ben.
 
Reply With Quote
 
george972@mailinator.com
Guest
Posts: n/a
 
      05-25-2009
Hi

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

Regards,


On May 25, 6:21*pm, Ben Bacarisse <(E-Mail Removed)> wrote:
> (E-Mail Removed) writes:
> > #include<iostream>

>
> You are using C++ so you should post in comp.lang.c++.
>
> <snip>
> --
> Ben.


 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      05-25-2009
In article <RgBSl.30415$(E-Mail Removed)>,
Doug Miller <(E-Mail Removed)> wrote:
>In article
><(E-Mail Removed)>,
>(E-Mail Removed) wrote:
>>Hi
>>
>>You guys need to chill the **** out brothers. Replace fstream with
>>open/read/write if you want, its just the same.

>
>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".

 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      05-25-2009
On May 25, 2009 13:48, in comp.lang.c, (E-Mail Removed)
((E-Mail Removed)) wrote:

> 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. ------


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-25-2009
(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
Doug Miller
Guest
Posts: n/a
 
      05-25-2009
In article <gveno1$p12$(E-Mail Removed)>, (E-Mail Removed) (Kenny McCormack) wrote:
>In article <RgBSl.30415$(E-Mail Removed)>,
>Doug Miller <(E-Mail Removed)> wrote:
>>In article
>><(E-Mail Removed)>,
>>(E-Mail Removed) wrote:
>>>Hi
>>>
>>>You guys need to chill the **** out brothers. Replace fstream with
>>>open/read/write if you want, its just the same.

>>
>>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.


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.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-25-2009
(E-Mail Removed) (Doug Miller) writes:
> In article <gveno1$p12$(E-Mail Removed)>,
> (E-Mail Removed) (Kenny McCormack) wrote:

[more of the same]
>
> Oh, for crying out loud.

[...]

Please don't feed the troll.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input from file and output to file - VHDL Emel VHDL 2 01-29-2010 08:01 AM
several input-output questions Jess C++ 10 06-18-2007 09:56 AM
input and output questions about file Dic4000@163.com C++ 5 02-24-2007 09:10 PM
input and output questions about file Dic4000@163.com C Programming 6 02-24-2007 05:18 PM
java input and output stream to the same file at the same time? Krick Java 1 08-15-2003 05:55 PM



Advertisments