ios::noreplace (File I/O)

This is a discussion on ios::noreplace (File I/O) within the C++ Programming forums, part of the General Programming Boards category; Why is it saying that ios::noreplace is not a member of 'std::basic_ios<_Elem, _Traits>' I read in MSDN help files that ...

  1. #1
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483

    ios::noreplace (File I/O)

    Why is it saying that ios::noreplace is not a member of 'std::basic_ios<_Elem, _Traits>'

    I read in MSDN help files that it is no longer defined in the new library files.

    Where is it defined? or what value does it hold?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    One result from a search on the term ios::noreplace.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    ok
    thanks

    But now i get a different error..

    Code:
    ifstream blah;
    if(!(blah.open("blah.txt")))
    {
    blah blah();
    }
    
    ERROR:
    blah.cpp(33): error C2171: '!' : illegal on operands of type 'void'
    aslo:
    blah.cpp(33): error C2451: conditional expression of type 'void' is illegal
            Expressions of type void cannot be converted to other types

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Code:
    ifstream blah;
    if(!(blah.open("blah.txt")))
    {
    blah blah();
    }
    ERROR:
    blah.cpp(33): error C2171: '!' : illegal on operands of type 'void'
    aslo:
    blah.cpp(33): error C2451: conditional expression of type 'void' is illegal
    Expressions of type void cannot be converted to other types


    The error tells you exactly what is going on. The return type of the open file stream member function is type void. You can't perform a logical not (!) on a type void. It doesn't make any sense. This is what the messages are telling you.

    Try using the is_open member function instead:

    Code:
    ifstream blah;
    blah.open("blah.txt");
    if(!blah.is_open())
    {
    blah blah();
    }
    Or this (a little bit of a shortcut):

    Code:
    ifstream blah("blah.txt");
    if(!blah.is_open())
    {
    blah blah();
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    It doesn't work for some reason!
    The file is there but it still executes the code in the if statement!
    also when i try to write from file to a string it doesn't do anything
    Code:
    string str, str1;
    ifstream blah("blah.txt");
    blah >> str1 >> str2;
    cout << str1 << str2;
    
    Content of 'blah.txt':
    Text1
    Text2
    But when i run it nothin shows up?
    Last edited by mrafcho001; 06-05-2005 at 09:56 AM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Always check for success when doing input or opening a file:
    Code:
    ifstream blah("blah.txt")
    
    if (!blah) {
      std::cerr<<"Error opening file\n";
      // Do something, probably terminate
    }
    If you get the error then the most likely problem is that the file isn't where the program is looking for it. And if the file can't be opened, the stream is not in a good state, therefore any attempt to read from it will do nothing.
    My best code is written with the delete key.

  7. #7
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Thanks guys

    Just last question (I know, sorry)

    Why doesn't the ifstreammembers accept strings?
    or the string.c_str()?

    Is there anyway to use a strings with the ifstream members?

    How do i store everything in the file in 1 string?
    Last edited by mrafcho001; 06-05-2005 at 01:39 PM.

  8. #8
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    string mystring; <--- mystring is a class object

    whereas

    char mycstring[42]; <--- is just an array of characters



    so when you do stuff like
    Code:
      myifstream.open(mystring);    // open( ) doesn't know / isn't prototyped to accept a string class variable 
    .open( ) is expecting a null terminated array of characters.. A string class variable can normally simulate this using overloaded <<, >>, =, +=, [], and == operators. But on occasions where a function is expecting a null terminated character array, you can call the c_str( ) funtion from your derived string class variable and it will return a pointer to a null terminated character array.

    So it's just a matter of one object being a class object vs. one being a simple array
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    >> Why doesn't the ifstreammembers accept strings? or the string.c_str()?
    It does accept the result of .c_str(). If it isn't working for you, post the code and error.

    Also, make sure you #include <string> for the string class. If you were trying to use ios::noreplace from <fstream.h> you might have incorrectly been trying to use <string.h>.
    Last edited by Daved; 06-05-2005 at 11:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 03:47 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 04:56 AM

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