I am working on a module program that has a function that opens a file
then the next file is to read the names from txt. file
HUGH JACKMAN
LUCY LIU
HEIDI KLUM
BONNIE RAIT
DENZEL WASHINGTON
AL PACINO
WOODY ALLEN
EMMA WATSON
JOHN BARROWMAN
PAUL MCCARTNEY
PAULA ABDUL
JULIA ROBERTS
RUPERT GRINT
DANIEL RADCLIFFE
ERIC CLAPTON
JAKE GYLLENHAAL
MEGAN FOX
MICKEY MOUSE
KATIE HOLMES
CHRISTIAN BALE
MICHELLE PFEIFFER
BRUCE SPRINGSTEEN
MICHAEL KORS
JOHN CLEESE
BLAKE LIVELY
Into an array guestlist there are 25 elements
I am getting a undeclared identifier error inFile but infile worked fine in my initial function.
Here is my code
Code:/* Global Headers*/ #include <iostream> // include standard I/O library #include <fstream> // opening and closing files #include <cstdlib> #include <string> // set string class #include <stdlib.h> using namespace std; /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Global Constants */ const int NUM_GUESTS = 25 ; // number of guests on list const string BLANKS = " " ; // input spacing std::string guestlist[NUM_GUESTS]; // array int count; //for counter /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Function Prototypes */ void PrintIntro(); void OpenFile(ifstream& inFile); void ReadFile (); /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* main function */ int main () { ifstream inFile; // input data file //Print intro for user PrintIntro(); //open file that contains stars name OpenFile(inFile); //read and file array// ReadFile(); return 0; } /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Functions */ void PrintIntro() { // Print intro cout << "********************************************************" << endl; cout << " *The L.A. Enquirer Welcomes the Top 25 Hollywood Stars*" << endl; cout << "********************************************************" << endl; return; } // Print intro /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ void OpenFile(ifstream& inFile) { inFile.open("partyGuests.txt"); if (!inFile) { cout<< ("This file is unaccessable at this time!")<< endl; exit (1); } else cout<< "file open" << endl; return; } /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ // read from file and build list// void ReadFile(string) {while(!inFile.eof()) Infile.getline(guestlist,NUM_GUESTS); cout << guestlist << endl; //close file inFile.close(); return }
error messages as follows (if I remove final function it compiles and debugs)
Code:1>c:\documents and settings\carol rose\my documents\visual studio 2008\projects\party5\party5\party5.cpp(139) : error C2065: 'inFile' : undeclared identifier 1>c:\documents and settings\carol rose\my documents\visual studio 2008\projects\party5\party5\party5.cpp(139) : error C2228: left of '.eof' must have class/struct/union 1> type is ''unknown-type'' 1>c:\documents and settings\carol rose\my documents\visual studio 2008\projects\party5\party5\party5.cpp(139) : fatal error C1903: unable to recover from previous error(s); stopping compilation
This is a prject and I have limited knowledge I would like to get over this hump
and have the array set so I can fill the parallel array
and do the comparisons.
This program is to have a user enter a name and test for present or absent
if absent change to present.
Hope this post is not to wordy thought it might help to know where it was heading.
Thanks for any help
Pistol1