Help with School Project

This is a discussion on Help with School Project within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm a student and fairly new to C++. I need help with this school assignment. It's supposed to demonstrate ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    Help with School Project

    Hi,

    I'm a student and fairly new to C++. I need help with this school assignment. It's supposed to demonstrate fstream by reading the contents of different files and displaying them on the monitor. It works perfectly the first time, but after that I get an error message. Please help.

    Thanx,
    John Touron


    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    using namespace std;
    
    class FILEMANIP 
    {
    	char filePath[100];
    	ifstream input;
    
    public:
    	void GetFilePath();
    	void OpenFile() { input.open(filePath); }
    	int CheckOpen();
    	void DisplayContents();
    	void CloseFile() { input.close(); }
    ; 
    } fileManip;
    
    bool cont();
    
    int main ()
    {
    	do
    	{
    		fileManip.GetFilePath();
    		fileManip.OpenFile();
    		fileManip.CheckOpen();
    		fileManip.DisplayContents();
    		fileManip.CloseFile(); 
    	} while (cont());
    	
    	return 0;
    }
    
    bool cont()
    {
    	char x;
    	
    	cout << "Do you wish to display the contents of another file (Y/N)?  ";
    	cin >> x;
    
    	switch (toupper(x))
    	{
    	case 'Y':
    		cout << endl;
    		return true;
    	default:
    		cout << endl;
    		return false;
    	}
    }
    
    void FILEMANIP::GetFilePath()
    {
    	int x = 0;
    	
    	cout << "Enter path and file name of the file to be read from:\n\n";
    	cin.getline(filePath,100);
    	
    	cout << endl;
    }
    
    
    int FILEMANIP::CheckOpen()
    {
    	if (input.fail())
    	{
    		cerr << "*** ERROR: Cannot open " << filePath
    			 << " for input.\n";
    
    		return EXIT_FAILURE;
    	}
    
    	return 0;
    }
    
    void FILEMANIP::DisplayContents()
    {
    	char nextChar;
    
    	input.get(nextChar);
    
    	while (!input.eof())
    	{
    		cout << nextChar;
    		input.get(nextChar);
    	}
    	
    	cout << endl << endl;
    }

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    28
    What is the error message?

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    Error Message

    Sorry for not posting the error message.

    A window pops open with the following:

    Microsoft Visual C++ Debug Library

    Debug Assertion Failed!

    Program: ...isual Studio\MyProjects\B8A_inputFile\Debug\B8A_inputFil e.exe
    File: fopen.c
    Line: 54

    Expression: *file !=_T('\0')

    For information on... blah blah blah.

    Abort Retry Ignore

    Thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  3. Please, suggest a project .
    By Dragon227Slayer in forum Tech Board
    Replies: 1
    Last Post: 06-12-2004, 10:48 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM
  5. Question about going to a technical school
    By Goalie35 in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:34 AM

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