Thread: input file error message

  1. #1
    Registered User
    Join Date
    May 2002

    input file error message

    im having some difficulties with fstream and giving some specific error messages:

    say for instance i have:

    ifstream in;

    i need two error messages
    1) to test if the file doesnt exist, print 'file does not exist'
    2) if the file exist, but unable to be access (perhaps in read only mode)

    ive been trying to work with for if the file does not exist, but it also seems to work for there any other ways of getting these two error messages?

  2. #2
    I'm Back
    Join Date
    Dec 2001
    1. you can use ios::nocreate and ios::noreplace ->

    ios::nocreate -> wont create file, if file doesn't exists
    ios::noreplace -> wont replace file, if file exists

    2. use good/bad/fail -->

    if(!in.good() || in.bad() ||
    cout<<"something's wrong";


    cout<<"something's wrong";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM