Thread: Problems with c-style strings

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by possik View Post
    ok , i checked the file stream.
    Code:
     fstream f;
    
            f.open(filen.c_str(),ios::out|ios::in|ios::binary);
    		num=f.fail();
    after these commands in main() function, the fail bit of the stream is set to 1.
    but i don't why?
    which types of error could it be?

    could it be the string converting to c-style string/?
    The conversion to c-style string in the filename is necessary, not a problem. If you expect this filename to exist, that should be something you need to check (i.e. that it does exist). Your current working directory may not allow files to be created there, depending on where you're running this from. I wish open would set errno.

  2. #17
    Registered User
    Join Date
    May 2011
    Posts
    7
    YAYAYYAYAYAYYAYA i fixed the problem!!!

    so the problem was that i opened the file in ios::in|ios:ut|ios::binary

    but the files weren't yet created , so the compiler opened the file with a failbit!!!
    so instead of
    Code:
     fstream f;
    
     f.open(filen.c_str(),ios::out|ios::in|ios::binary);
    i made something like this :

    Code:
    fstream f;
    
            f.open(filen.c_str(),ios::out);
    		f.close();
    		f.open(filen.c_str(),ios::in|ios::out|ios::binary);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clarification with C-style Strings
    By StapleGun in forum C Programming
    Replies: 8
    Last Post: 10-30-2008, 07:46 PM
  2. Converting C++ Style strings...
    By LightsOut06 in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2005, 03:02 PM
  3. More problems with C style strings
    By mousey in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2003, 01:52 PM
  4. converting c style strings to c++ strings
    By fbplayr78 in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 03:13 AM
  5. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 12:26 PM