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
    Posts
    13

    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.

    Code:
    #include<iostream>
    #include<string>
    
    //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;
        cin>>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
        cout<<endl;
        
        //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){
                                  cout<<greeting;
                                  c +=greeting.size();
                        }else{
                              
                              //are we on the border?
                              if(r==0||r==rows-1||c==0||c=cols-1)
                              cout<<"*";
                        else
                          cout<<" ";
                        ++c;
                        }
                }
                
                cout<<endl;
        }
        return 0;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
     if(r==0||r==rows-1||c==0||c == cols-1)

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > 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
    Posts
    2,544
    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:
    Code:
    if(r==0||r==rows-1||c==0||c=cols-1)
    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:
    Code:
    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:
    Code:
     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, 06:32 PM
  2. pass be reference versus pass by value
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 01:03 PM

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