open file in class as user variable

need help openinf a file in a class

Page 1 of 1

2 Replies - 991 Views - Last Post: 10 May 2009 - 08:45 PM Rate Topic: -----

#1 jolygregnt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 09

open file in class as user variable

Posted 10 May 2009 - 06:34 PM

So i have to open a file in a class function, but I'm not sure how to do it.

Here is the class function that is giving me problems:
      void CustomerInfo::ReadInfo(char data[])
      {
	     char choice; //holder for yes/no variables
     	     customer>>arrivalTime;
	     if (arrivalTime==0)
	     {
	     	    cout<<"No more customers.";
		    exit(1);
	     }
	     customer>>name>>choice;
	     choice=toupper(choice);
	     switch (choice)
	    {
		    case 'Y': cardHolder=true;break;
		    case 'N': cardHolder=true;break;
	     }
	     customer>>seatsRequested>>choice;
	     choice=toupper(choice);
	     switch (choice)
	     {
	 	     case 'Y': split=true;break;
		     case 'N': split=true;break;
	     }	
	     customer>>payment;
     }


This is the function that im using to implement said class function:

     void LoadQueue(char data[])
     {	
	    ifstream customer;
	    customer.open(data);
 	    CustomerInfo nextcustomer;
	    while (nextcustomer.GetArrivalTime()!=0)
	    {
		nextcustomer.ReadInfo("CustomerInfo.txt");
		Master.Enqueue(nextcustomer);
	     }
	     customer.close();
     }


Here are the errors I'm getting:
tickets\customerinfo.cpp(26) : error C2065: 'customer' : undeclared identifier
tickets\customerinfo.cpp(32) : error C2065: 'customer' : undeclared identifier
tickets\customerinfo.cpp(39) : error C2065: 'customer' : undeclared identifier
tickets\customerinfo.cpp(46) : error C2065: 'customer' : undeclared identifier



any ideas where i went wrong???

*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 11 May 2009 - 05:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: open file in class as user variable

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2032
  • View blog
  • Posts: 5,435
  • Joined: 27-December 05

Re: open file in class as user variable

Posted 10 May 2009 - 08:06 PM

The compiler error messages are telling you exactly what is wrong. You are supposed to read them. Here is the beginning of your function:
void CustomerInfo::ReadInfo(char data[])
{
char choice; //holder for yes/no variables
customer>>arrivalTime;  // this must be line 26
//...

What is "customer"?
You are using the identifier (variable name) "customer", but "customer" is not passed to the function as an argument, and "customer" is not declared in the function, so as far as the compiler knows, no variable named "customer" exists in this function.
Was This Post Helpful? 0
  • +
  • -

#3 jolygregnt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 09

Re: open file in class as user variable

Posted 10 May 2009 - 08:45 PM

ok the variable is not defined but how do i use the ifstream in the class code or pass it as a variable?

should i use a char array? i tried that and it didn't work.
or a string?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1