Ivalue annoyance

This is a discussion on Ivalue annoyance within the C++ Programming forums, part of the General Programming Boards category; Been moving thru Accelerated C++ and Iím a little far thru, this problem annoys me though. This is the program ...

  1. #1
    Registered User Daniel Primed's Avatar
    Join Date
    Jun 2005

    Ivalue annoyance

    Been moving thru Accelerated C++ and Iím a little far thru, this problem annoys me though. This is the program that you make in chapter 2 which adds a frame to an inputted name etc etc Also says hello. Dev C++ says that thereís an error with it. Being that there is no I value in the assignment. The line under the comment: are we on the border?. Can someone help me with this I always seem to trip up on the I value stuff. Can I get an explanation on it as well for future reference. Thanks very much.

    //say what standard-library names we use
    using std::cin;          using std::endl;
    using std::cout;         using std::string;
    int main()
        //ask for persons name
        cout<<"Please enter your first name: ";
        //read the name
        string name;
        //build the message that we intend to write
        const string greeting="Hello, "+name+ "!";
        //the number of blanks surrounding the greeting
        const int pad=1;
        //the number of rows and columns to write
        const int rows=pad *2 +3;
        const string::size_type cols=greeting.size() + pad * 2 + 3;
        //write blank line of seperation
        //write rows rows output
        //invariant:we have written r rows so far
        for(int r=0; r !=rows; ++r){
                string::size_type c=0;
                //invariant: we have written c characters so far in the current row
                while(c !=cols){
                        //is it time to write the greeting?
                        if(r==pad + 1 && c==pad + 1){
                                  c +=greeting.size();
                              //are we on the border?
                          cout<<" ";
        return 0;

  2. #2
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
     if(r==0||r==rows-1||c==0||c == cols-1)

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > if(r==0||r==rows-1||c==0||c=cols-1)
    Perhaphs it's the missing = in c == cols-1

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    It's L-Value(elle-value) not I-Value(eye-value). The L stands for left. A left-value is a value that can appear on the left side of an assignment (left = right). The reason that you get a non l-value warning on this line:
    is because of the C order of precedence. The logical OR operator ( || ) has a higher precedence than the assignment operator ( = ). We can add brackets to show how the compiler tries to evaluate this line:
    if( ((((r==0) || (r==rows-1)) || (r==0)) || c) = (cols-1) )
    Obviously, we can see that the value on the left side of the assignment operator (highlighted) is not an l-value. Assuming we really wanted to do an assignment we could add brackets to force the correct order of precedence:
     if(r==0||r==rows-1||c==0|| (c=cols-1))

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX SDK Error, annoyance
    By Hidden-Shadow in forum Game Programming
    Replies: 5
    Last Post: 10-11-2003, 07:32 PM
  2. pass be reference versus pass by value
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 02:03 PM

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