Thread: Atwrkhrdlywrking

  1. #1
    WORKBREAK
    Guest

    Atwrkhrdlywrking

    //HOW DO YOU MAKE IT SO THE FILE WILL OUTPUT SOMETHING
    //IF THE FILE IS EMPTY
    #include <iostream>
    #include <fstream>

    using namespace std;

    main()
    {

    int sum = 0;
    int x;
    ifstream inFile;
    inFile.open("input.txt");


    if(!inFile)//can file be opened
    {
    cout<<"Sorry cannot open input file. Program terminating";
    exit(0);
    }



    //if(inFile.eof()) //file exists but is empty
    //{
    // cout<<"Your file is empty";
    // exit(0);
    //}


    while (inFile>>x)








    sum = sum + x;
    cout<<endl;
    cout<<sum;
    inFile.close();

    return 0;

    }

  2. #2
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    Try to read something, if you hit EOF right away then print that the file is empty.

Popular pages Recent additions subscribe to a feed