odd I/O compile error

This is a discussion on odd I/O compile error within the C++ Programming forums, part of the General Programming Boards category; I get this odd compile error: 21 C:\programs\testspil\testspil.cpp `noreplace' is not a member of type ` Code: line 21: ofstream ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    20

    odd I/O compile error

    I get this odd compile error:

    21 C:\programs\testspil\testspil.cpp `noreplace' is not a member of type `

    Code:
    line 21: ofstream a_file("wins.txt", ios::noreplace);
    help appreciated

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I get this odd compile error
    It's hardly odd at all. noreplace is not standard C++, so you're probably using a compiler that doesn't support it. Think about why you're trying to use noreplace and see if you really need it. Chances are that you don't.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    20
    how else would you check if the file is already there? It's a statistics file where I want to store int's... So if it's the first time running the program then it should create a statistics file, but if it's already there I don't want to trunctate it...

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    So use ios::app then. Have a look at this page for the different flags.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >how else would you check if the file is already there?
    Use something nonportable and implementation-dependent that we can't describe because you haven't give us any more detail about your compiler. Or you could simply open the file for reading. If the open is successful then the file exists, if it fails you'll simply have to assume it did so because the file doesn't yet exist.

    >but if it's already there I don't want to trunctate it...
    See? You didn't really need noreplace after all, just use ios_base::app.
    My best code is written with the delete key.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Is it recommended to use ios::app or ios_base::app?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Is it recommended to use ios::app or ios_base::app?
    ios_base::app is recommended simply because the C++ standard makes no mention of ios::app being valid that I can remember.
    My best code is written with the delete key.

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    That's a good enough reason for me then.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Quote Originally Posted by Prelude
    >Is it recommended to use ios::app or ios_base::app?
    ios_base::app is recommended simply because the C++ standard makes no mention of ios::app being valid that I can remember.
    If you don't mind, I'll correct myself before someone else does. After looking at the standard, both are valid. ios_base is where the openmode app is defined, but ios is a typedef defined as
    Code:
    typedef basic_ios<char> ios;
    Where basic_ios is a template class derived from ios_base. So both will work, both are standard, and which you use looks to be a matter of style.
    My best code is written with the delete key.

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Gah! Prelude was wrong! The world's going to heck in a handbasket!
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Not wrong, just not completely correct
    Last edited by Thantos; 06-05-2004 at 11:32 PM.

  12. #12
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >Not wrong, just completely correct
    I'm guessing you missed a 'not' in there.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    /whistle Whatcha mean?

  14. #14
    Registered User
    Join Date
    May 2004
    Posts
    20
    I use Bloodshed Dev-C++

    thx for the help, but...

    in line 25 below:

    Code:
    23    ifstream winfilein;
    24    
    25    if(!(winfilein.open("wins.txt", ifstream::in)))
    26    {
    27        winfilein.close();
    28        blahblah;
    29    }
    is there a voide value that isn't ignored?

    I've looked up the function, but it seemed perfectly fine...
    Is it because of the IF statement?

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It is perfectly fine.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21