input and output questions about file

Discussion in 'C Programming' started by george972@mailinator.com, May 25, 2009.

  1. Guest

    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?
    , May 25, 2009
    #1
    1. Advertising

  2. Lew Pitcher Guest

    On May 25, 2009 12:56, in comp.lang.c,
    () wrote:

    > 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. ------
    Lew Pitcher, May 25, 2009
    #2
    1. Advertising

  3. Flash Gordon Guest

    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
    Flash Gordon, May 25, 2009
    #3
  4. writes:

    > #include<iostream>


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

    <snip>
    --
    Ben.
    Ben Bacarisse, May 25, 2009
    #4
  5. Guest

    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 <> wrote:
    > writes:
    > > #include<iostream>

    >
    > You are using C++ so you should post in comp.lang.c++.
    >
    > <snip>
    > --
    > Ben.
    , May 25, 2009
    #5
  6. In article <RgBSl.30415$>,
    Doug Miller <> wrote:
    >In article
    ><>,
    > 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".
    Kenny McCormack, May 25, 2009
    #6
  7. Lew Pitcher Guest

    On May 25, 2009 13:48, in comp.lang.c,
    () 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. ------
    Lew Pitcher, May 25, 2009
    #7
  8. James Kuyper Guest

    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.
    James Kuyper, May 25, 2009
    #8
  9. Doug Miller Guest

    In article <gveno1$p12$>, (Kenny McCormack) wrote:
    >In article <RgBSl.30415$>,
    >Doug Miller <> wrote:
    >>In article
    >><>,
    >> 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.
    Doug Miller, May 25, 2009
    #9
  10. (Doug Miller) writes:
    > In article <gveno1$p12$>,
    > (Kenny McCormack) wrote:

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

    [...]

    Please don't feed the troll.

    --
    Keith Thompson (The_Other_Keith) <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"
    Keith Thompson, May 25, 2009
    #10
  11. Doug Miller Guest

    In article <gveno1$p12$>, (Kenny McCormack) wrote:

    >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.
    Doug Miller, May 25, 2009
    #11
  12. In article <blargg.ei3-2505091657160001@192.168.1.4>,
    blargg <> wrote:
    >george972 wrote:
    >> Ben Bacarisse wrote:
    >> > writes:
    >> > > #include<iostream>
    >> >
    >> > You are using C++ so you should post in comp.lang.c++.

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

    >
    >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.
    Kenny McCormack, May 25, 2009
    #12
  13. In article <nHESl.17679$%>,
    Doug Miller <> wrote:
    >In article <gveno1$p12$>,
    >(Kenny McCormack) wrote:
    >
    >>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.


    I don't pretend to be anything other than what I am - a commentator on
    the social norms of this newsgroup.
    Kenny McCormack, May 25, 2009
    #13
  14. Doug Miller Guest

    In article <gvf725$3mo$>, (Kenny McCormack) wrote:
    >In article <nHESl.17679$%>,
    >Doug Miller <> wrote:
    >>In article <gveno1$p12$>,
    >>(Kenny McCormack) wrote:
    >>
    >>>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.

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

    IOW -- a net-nanny.

    <plonk>
    Doug Miller, May 26, 2009
    #14
  15. BartC Guest

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


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

    --
    bart
    BartC, May 26, 2009
    #15
  16. Eric Sosman Guest

    wrote:
    > 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?

    --
    Eric Sosman
    lid
    Eric Sosman, May 26, 2009
    #16
  17. luserXtrog Guest

    On May 25, 12:48 pm, wrote:
    > 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 <> wrote:
    >
    > > writes:
    > > > #include<iostream>

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

    >
    > > <snip>
    > > --
    > > Ben.

    >
    >


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

    --
    laser chicken
    luserXtrog, May 26, 2009
    #17
  18. Guest

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

    On 25 May, 18:48, wrote:
    > 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.


    > On May 25, 6:21 pm, Ben Bacarisse <> wrote:
    >
    >
    >
    > > writes:
    > > > #include<iostream>

    >
    > > You are using C++ so you should post in comp.lang.c++.
    , May 26, 2009
    #18
  19. Guest

    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,


    On May 26, 8:35 am, wrote:
    > please don't top-post. Post your reply *after* what
    > you are replying to.
    >
    > On 25 May, 18:48, wrote:
    >
    > > 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.
    >
    > > On May 25, 6:21 pm, Ben Bacarisse <> wrote:

    >
    > > > writes:
    > > > > #include<iostream>

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

    >
    >
    , May 26, 2009
    #19
  20. In article <> writes:
    > 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?
    --
    dik t. winter, cwi, science park 123, 1098 xg amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
    Dik T. Winter, May 26, 2009
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Emel
    Replies:
    2
    Views:
    5,847
    nish a
    Jan 29, 2010
  2. Krick
    Replies:
    1
    Views:
    1,440
    John C. Bollinger
    Aug 15, 2003
  3. Replies:
    6
    Views:
    437
    CBFalconer
    Feb 24, 2007
  4. Replies:
    5
    Views:
    388
  5. Jess
    Replies:
    10
    Views:
    572
Loading...

Share This Page