"error C2106: '=' : left operand must be l-value"

This is a discussion on "error C2106: '=' : left operand must be l-value" within the C++ Programming forums, part of the General Programming Boards category; i keep getting that error everytime. (error C2106: '=' : left operand must be l-value) i want to take specific ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    "error C2106: '=' : left operand must be l-value"

    i keep getting that error everytime. (error C2106: '=' : left operand must be l-value) i want to take specific feilds from the data i read in, and put it into another struct. but when i get to the productlineid it keeps erroring. both are set to char of [10]

    here's what im doing

    Code:
    class Data		//class used to take in the data from the file
    {
    	private:
    		struct Rawdata
    		{
    		int ordernumber;
    		char date[10];
    		int orderedproductid;
    		float priceperproduct;
    		int numberordered;
    		char productlineid[10];	//data in this field must be 10 chars long so ----'s are added to the text
    		int customerid;	
    		};              		// file so each product id has 10 chars so it properly reads it
    	public:
    		Data( );  //constructor
    		void ReadFile(int);
    		ifstream transactionin;  // Allows class access to tranaction file
    };
    
    class Report		//class used to sort the data and print it out
    {
    	public:
    		struct Transaction	// Declaration of Transaction Structure
    		{
    		int orderedproductid;
    		int numberordered;
    		float priceperproduct;
    		char productlineid[10];	//data in this field must be 10 chars long so ----'s are added to the text
    		};						// file so each product id has 10 chars so it properly reads it
    	
    		Transaction datain[10];
    		Report();  //constructor
    		void SortData();
    		void PrintData();
    };
    
    .............cut out not relevent code
    
    void Data::ReadFile(int MAXRECS)
    {
    int Record = 0;
    
    transactionin.open("transaction.h", ios::in, ios::nocreate); //open transaction.h file
    if (transactionin == NULL)		//check if file opened correctly
    {
    	cout << "\nThe file transaction.h was not opened, please check the file" << endl;
    	exit(1);
    }
    
    	int LINECOUNTER = 0;		//counter to increase the structure
    	char NEWLINE = '\n';
    	int ch;
    	char line[100];
    
    while( (ch = transactionin.peek()) != EOF)  // this counts how many lines are
    {											// in the transaction.h data file
    	transactionin.getline(line,100,NEWLINE);
    		LINECOUNTER++;
    }
    transactionin.close();
    
    
    Rawdata record[10];   // constant problem!!!!!!!
    
    
    transactionin.open("transaction.h", ios::in, ios::nocreate);
    while (Record < LINECOUNTER)  //reads the text file until MAXRECS has been reached
    {					     // putting the data into the appropriate struct array position
      transactionin >> record[Record].ordernumber; 
      transactionin >> record[Record].date ;
      transactionin >> record[Record].orderedproductid ;
      transactionin >> record[Record].priceperproduct ;
      transactionin >> record[Record].numberordered; 
      transactionin >> record[Record].productlineid ;
      transactionin >> record[Record].customerid ;
      Record++;						// increment the record counter
    }
    
    transactionin.close();   //close the data file transaction.h
    
    Record=0;
    Report::Transaction datain[10];
    
    while(Record < LINECOUNTER)
    {
    datain[Record].orderedproductid  = record[Record].orderedproductid;
    datain[Record].numberordered = record[Record].numberordered ;
    datain[Record].priceperproduct = record[Record].priceperproduct;
    datain[Record].productlineid = record[Record].productlineid ;   //THIS IS WHERE ERRROR HAPPENS
    Record++;
    }
    
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You can't assign strings using the = operator. Use strcpy() instead.

    strcpy(Destination, Source) if I remember it right.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    ahhh thank you!

    i am way out of my league on this assignment, but trying to do the best i can.

    thanks again!

    Jon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 07:01 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-07-2002, 12:28 AM

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