error <,,.>

This is a discussion on error <,,.> within the C++ Programming forums, part of the General Programming Boards category; Can somebody tell me whats is the error? after if {..... C:\Documents and Settings\ashida\My Documents\MASTER C++\main2.cpp(67) : error C2106: '=' ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    21

    error <,,.>

    Can somebody tell me whats is the error?

    after if
    {.....
    C:\Documents and Settings\ashida\My Documents\MASTER C++\main\412.cpp(67) : error C2106: '=' : left operand must be l-value


    Code:
    #include <iostream>   // std::cout
    #include <fstream>
    #include <iomanip>
    #include <string>    // std::string
    #include <vector>    // std::vector<>
    #include <algorithm> //std::for each()
    using namespace std; // import "std" namespace into global namespace
    
    struct exam
    {
    int examid;
    vector <int> total;
    };
    
    void SwapMembers (int items[], int index1, int index2)
    {
    	int temp;
    	temp=items[index1];
    	items[index1]=items[index2];
    	items[index2]=temp;
    }
    
    	int main() 
    	{
    	ifstream stream1("STA83SOLUTION.txt");
    		if ( !stream1.is_open())
    		{
    		cout << "While opening a file an error is encountered" << endl;
    		} 
    			else 
    			{
    			cout << "Fail Di buka....." << endl;
    			}
    	vector <exam> exams;
    	exam aExam;
       int tempExamID;
        int tempTotal;
        stream1 >> tempExamID >> tempTotal;
        aExam.examid = tempExamID;
        aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
        while (stream1 >> tempExamID >> tempTotal)
        {
            if(tempExamID != aExam.examid)
            {
            exams.push_back(aExam); // no more exam codes for this student.  Add aStudent to students vector
            aExam.total.clear();
            aExam.examid = tempExamID;
            }
            aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
        }
        exams.push_back(aExam); // no more exam codes for this student.  Add aStudent to students vector
        stream1.close(); // We have read the entire file, so time to close it.
    {
    	ofstream myfile;
    	myfile.open("411.txt");
    	
    	int temp, flag;
    	if (myfile.is_open())
    	{
    		for (size_t i = 0; i < exams.size(); i++) 
    		{
    			for (size_t j = 0; j<exams.at(i).total.size(); j++) 
    			{
    				if (exams.at(i).total.size() < exams.at(i).total.size()+1)      // ascending order simply changes to <
    				{ 
                        temp = exams.at(i).total.size();             // swap elements
                        exams.at(i).total.size() = exams.at(i).total.size()+1;
                        exams.at(i).total.size()+1 = temp;
                        flag = 1;               // indicates that a swap occurred.
                    }
    
    		cout<<"\n"<<i+1<<":"<<" "<< exams.at (i).total.at(j)<<"\t"; // output list of exam codes for this student
    	  	cout<<" "<< exams.at (i).total.at(j)<<"\t";
    			}
    		}
    	}
    					
    cin.get();
    return 0;
    }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,596
    You appear to be trying to swap the sizes of the total members of the exam objects when you probably want to swap the total members instead.

    Oh, and kindly indent your code more consistently.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    It helps to tell at what line the error is occuring.
    And the whole indentation is a mess. How did you mess it up so badly whe Visual Studio indents for you? Let it indent for you instead of messing around with it yourself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,596
    It helps to tell at what line the error is occuring.
    Line 67, according to the error message... at least that part was included, I get rather frustrated when people cut it off thinking it makes things clearer.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    So it says, but I don't want to count the lines and a quick look over the horrible code didn't make anything suspicious point out. I might just have missed it.
    Ah, I see it now, thanks to copying it to notepad and using goto line. It's as laserlight says. You're trying to assign a new value to a function, which is impossible.
    But in the future, try to mark the line where the error occurs.
    Last edited by Elysia; 04-16-2008 at 02:06 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,596
    So it says, but I don't want to count the lines and a quick look over the horrible code didn't make anything suspicious point out. I might just have missed it.
    Visual Studio or any programming text editor worth its bits can give you a line count pretty quickly, methinks. The question then is whether the error message with line number given corresponds to the given source, and in this case it appears to correspond.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,659
    So it says, but I don't want to count the lines
    In effect, "I can't be bothered to help."

    size() is self-maintained, and you can't swap what is a literal number here. Actually swap the object.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Yeah, but at typing time, I'm not home, so Visual Studio or some other tools are unavailable to me. Although when I thought about it, notepad worked fine.

    Quote Originally Posted by citizen View Post
    In effect, "I can't be bothered to help."
    If you want to put it that way, fine. But it's also my free time, and I'm doing for free, so I'm not obligated to go to extreme lengths, if I feel it is so, to help. A little more from the who who needs help doesn't hurt.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,659
    If you want to put it that way, fine. But it's also my free time, and I'm doing for free, so I'm not obligated to go to extreme lengths, if I feel it is so, to help. A little more from the who who needs help doesn't hurt.
    Keeping quiet would have also been a decent alternative, since you really had nothing other than that to say, and the fact that it had been mentioned before.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    21

    error..

    so...the error? how to make a correction?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by citizen View Post
    Keeping quiet would have also been a decent alternative, since you really had nothing other than that to say, and the fact that it had been mentioned before.
    I did point out two other things - namely it's more helpful to point out where the error is and using Visual Studio to indent for you instead of manually.
    And I'm not overzealous like some other members who think that it should be made a rule not to reply on posts that aren't helpful in describing the problem.

    Quote Originally Posted by nurulshidanoni View Post
    so...the error? how to make a correction?
    I think you've been told. You shouldn't swap the "size." You should swap the total member instead. The object.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,659
    I love you too.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    With g++, I get:
    t.cpp:67: error: non-lvalue in assignment
    t.cpp:68: error: non-lvalue in assignment
    Lines 67 and 68 are these:
    Code:
                        exams.at(i).total.size() = exams.at(i).total.size()+1;
                        exams.at(i).total.size()+1 = temp;

    As was mentioned before, I don't think the size() is what you want to use here.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Banned
    Join Date
    Nov 2007
    Posts
    678
    or ... may be size() is supposed to return a reference?

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    No, that's the size() of the vector standard class.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 12:12 PM
  2. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 07:48 AM
  3. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 01:06 PM
  4. electricity > AC circuits > tesla coil
    By dbaryl in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 03-14-2002, 01:16 PM

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