Thread: Help with program

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    43

    Help with program

    ok i am in the beginning stages and right now im just trying to make sure that my program opens a file for reading and opens a file for me to write output to but for some reason im gettin 26 errors using msv C++. Can someone help?

    Code:
    #include <stdlib.h>
    #include <iostream>
    #include <iomanip.h>
    #include <fstream>
    
    using std ::cout;
    using std ::cin;
    using std ::cerr;
    using std ::ios;
    using std ::endl;
    using std ::ifstream;
    
    
    int main()
    {
    	//ifstream constructor opens file
    	ifstream inputFile("input.dat", ios:: in);
    
    	//exit program if unable to create file
    	if( !inputFile)
    	{
    		cerr<<File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	//ofstream constructor opens file
    	ofstream outputFile("output.dat", ios:: out);
    
    	//exit program if unable to create file
    	if( !outputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	return 0;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    - cerr<<File could not be opened"<<endl;
    There's a missing " in this line.
    Last edited by Hammer; 09-13-2002 at 09:58 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    Still giving me 6 errors

    Code:
    #include <stdlib.h>
    #include <iostream>
    #include <iomanip.h>
    #include <fstream>
    
    
    
    int main()
    {
    	
    
    	//ifstream constructor opens file
    	 ifstream inputFile("input.dat", ios::in);
    
    	//exit program if unable to create file
    	if( !inputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	//ofstream constructor opens file
    	 ofstream outputFile("output.dat", ios:: out);
    
    	//exit program if unable to create file
    	if( !outputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	return 0;
    }

  4. #4
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Actually just 1:

    Should be #include <fstream.h>
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    i keep gettin this error, please tell me the problem

    Code:
    #include <stdlib.h>
    #include <iostream.h>
    #include <iomanip.h>
    #include <fstream.h>
    
    
    
    int main()
    {
    	
    
    	//ifstream constructor opens file
    	 ifstream inputFile("input.dat", ios::in);
    
    	//exit program if unable to create file
    	if( !inputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	//ofstream constructor opens file
    	 ofstream outputFile("output.dat", ios:: out);
    
    	//exit program if unable to create file
    	if( !outputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	return 0;
    }
    Loaded 'ntdll.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
    The thread 0x66C has exited with code 0 (0x0).
    The program 'C:\Documents and Settings\Master\Debug\test.exe' has exited with code 0 (0x0).

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    you're running it in the debugger or something... but those aren't errors. It's just that the prog runs and quits before you notice. The dll thing happens when you start the prog in the debugger, and when it quits, it says that the app exited with code 0.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    how do i fix it?

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    try putting the line:

    cin.get();

    just before the the line:

    return 0;

    that should hold open so you can see the output until you push a key. As for the degugger thingy, I suspect there is a flag or a toggle or something to change. If you indicate what compiler you're using, somebody can probably tell what it is.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    im using visual c++

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    im trying to read data from a file in so i can do some things with it. the file looks like this:

    Ray L. Jones 3942
    Alice K. Brown 8300
    Gill R. Alante 4301

    So far the code i have looks like this :

    Code:
    #include <stdlib.h>
    #include <iostream.h>
    #include <iomanip.h>
    #include <fstream.h>
    
    void print(
    
    int main()
    {
    	
    
    	//ifstream constructor opens file
    	 ifstream inputFile("input.dat", ios::in);
    
    	//exit program if unable to create file
    	if( !inputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	//ofstream constructor opens file
    	 ofstream outputFile("output.dat", ios:: out);
    
    	//exit program if unable to create file
    	if( !outputFile)
    	{
    		cerr<<"File could not be opened"<<endl;
    		exit(1);
    	} //end if
    
    	char fName[10];
    	char mInitial[2];
    	char lName[10];
    	int empID;
    	
    	//read data from input file
    	while(inputFile>>fName>>mInitial>>lName>>empID)
    	{
    		
    	}
    
    
    	return 0;
    }

  11. #11
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Post the exact error message.
    Is what you posted before the _entire_ error log?

  12. #12
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    i fixed that problem now im trying to read in data like it says on my post above.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM