Thread: opening a file from hard drive

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    58

    opening a file from hard drive

    let me revise this. i need help closing the file, not opening it. when i try to run this i get an error message saying it expected a constructor or destructor before the "." token on the line that has inputFile.close(). what does that mean? how do i properly close this file?
    Code:
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    #include <ctype.h>
    
    using namespace std;
    bool myIsAlpha( char ch );
    bool myIsDigit( char ch );
    bool myIsUpper( char ch );
    int countPunct = 0,
    countAlpha = 0,
    countUpper = 0,
    countLower = 0,
    countChar = 0,
    countDigit = 0,
    countSpace = 0,
    countWhite = 0;
    char ch; 
    
    int main()
    {
    ifstream inputFile;
    
    //Open the input file. If it fails to open, display an error message and
    //end the program
    
    inputFile.open( "input.txt" );
    if( inputFile.fail() )
    {
    cout << "input.txt failed to open";
    exit( -1 );
    }
    
    if(ispunct(ch))
    {
    countPunct++;
    }
    
    else if(myIsAlpha(ch))
    {
    countAlpha++;
    }
    
    else if (myIsDigit(ch))
    {
    countDigit++;
    }
    else if (myIsUpper(ch))
    {
    countUpper++;
    }
    else if (islower(ch))
    {
    countLower++;
    }
    else if (isspace(ch))
    {
    countWhite++;
    }
    }
    
    //Close the input file
    
    inputFile.close();
    
    return 0;
    }
    Last edited by joeman; 03-04-2010 at 03:01 PM. Reason: confused

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM