errors when compiling, but I don't know what they mean

This is a discussion on errors when compiling, but I don't know what they mean within the C++ Programming forums, part of the General Programming Boards category; When I try to compile this, I get a ton of errors, but I don't know what they all mean ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    errors when compiling, but I don't know what they mean

    When I try to compile this, I get a ton of errors, but I don't know what they all mean
    Code:
        ////////////////////
       //Daniel Pritchett//
      //   COP 1220     //
     //   11-2-02      //
    ////////////////////
    
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    int main ()
    {
    
    	string SSN, LastName, FirstName, semester ;
    	int choice, students, ReferenceNum;
    	int RefNum[3];
    	
    	RefNum[0] = 111111;
    	RefNum[1] = 222222;
    	RefNum[3] = 333333;
    
    	ofstream outFile1;
    	ofstream outFile2;
    	ifstream inFile;
    
    	outFile1.open("a:sdntnfo.dat", ios::out);
    	inFile.open("a:sdntnfo.dat", ios::in);
    	outFile2.open("a:Record.txt", ios::out);
    
    	cout << "Please enter the Class term";
    	cin >> semester;
    	//heading
    	outFile2 << setw(6) << "Introduction to C"
    			<< setw(5) <<"\nTerm:" << semester
    			<< setw(5) << "\n\nReference# 11111"
    			<< "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First";
    
    	//loops so that the user can re-chose what operation they would like to do.
    	do
    	{
    		cout << "\nWould you like to\n1: Enter Student information\n"
    		<<"2: Read from file and create report"
    		<< "\n3: Quit\n";
    	cin >> choice;
    	switch(choice)
    	{
    		//outputs the first file, student database
    	case (1):
    		cout << "\nHow many students are you entering?";
    		cin >> students;
    		while(students != 0)
    		{
    
    		cout << "\nEnter the student's nine digit ID number: ";
    		cin >> SSN;
    		outFile1 << SSN;
    		cout << "\nEnter the student's Last then First name: ";
    		cin >> LastName >> FirstName;
    		outFile1 << " " << LastName << " " << FirstName;
    		cout << "\nEnter the student's Reference number: "
    			 <<"(note, only 111111, 222222, and 333333 are valid.\n)";
    		cin >> ReferenceNum;
    
    		//tests to see if number is correct
    		while((ReferenceNum!=RefNum[0]) && (ReferenceNum!=RefNum[1]) || (ReferenceNum!=RefNum[2]))
    		{
    			cout << "\nYou have entered an invalid number, please enter a correct one: ";
    			cin >> ReferenceNum;
    		} 
    		outFile1 << " " << ReferenceNum;
    		
    		students--;
    		}
    		break;
    
    		//generates reference number organized file
    	case (2):
    		
    		while (!inFile.eof())
    	{
    	inFile >> SSN >> LastName >> FirstName >> ReferenceNum;
    
    	outFile2 << right << SSN << right << setw(17) << LastName << right 
    			<< setw(16) << FirstName << "\n";
    
    	}
        break;
    
    	//quits
    	case(3):
    		exit(0);
    
    	//default, exits switch and displays switch options 
    	default:
    		cout << "\nYou did not enter a valid choise, please enter correct choice!";
    		break;
    	}
    	}
    	while(choice != 3);
    
    	outFile1.close();
    	outFile2.close();
    	inFile.close();
    
    }
    // in.seekg(0, ios::beg) OR  SeekToBegin() <----use to rewind to the beginning of the file.
    Last edited by indigo0086; 11-04-2002 at 05:01 PM.

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    I think some of it might be...

    You are mixing modern and deprecated header files...

    <string.h> should be <string> (Actually is should be cstring but thats a different header file entirely)
    <iomanip.h> should be <iomanip>
    <stdlib.h> should be <cstdlib>

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try doing this
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdlib>
    #include <iomanip>
    
    using namespace std;
    Don't use the .h extensions when you are using namespace std. Also many standard files are prefixed with "c" now like stdlib.h turns into <cstdlib> no .h. Try that out.

  4. #4
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Also...

    Code:
    case 2:
       exit(1);
    You should probably do this differently, its kinda bad like that, and especially if this is for a class you teacher should take points off for it.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    ok, thanks a lot I got it working. I didn't know why I put the .h in there, guess I have to be more careful with headers.

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    now it is giving this error

    Code:
    error C2143: syntax error : missing ';' before 'string'
    on the line wher it says
    Code:
    outFile2 << right << SSN << right << setw(17) << LastName << right 
    			<< setw(16) << FirstName"\n";

  7. #7
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Originally posted by indigo0086
    Code:
    outFile2 << right << SSN << right << setw(17) << LastName << right 
    			<< setw(16) << FirstName"\n";
    add another << before the \n escape sequence.

    Code:
    outFile2 << right << SSN << right << setw(17) << LastName << right << setw(16) << FirstName <<"\n";

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    -_-;;
    aye aye aye, and here I was looking through the whole code when it was right in front of me. Ok, now, time to try out arrays to see if they work. thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Replies: 4
    Last Post: 03-10-2008, 08:03 AM
  3. Quincy 2005: Compiling Errors
    By Thileepan_Bala in forum C Programming
    Replies: 6
    Last Post: 01-18-2008, 08:26 PM
  4. Replies: 2
    Last Post: 12-07-2004, 02:31 AM
  5. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 04:22 AM

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