Like Tree2Likes

must be a modifiable lvalue error

This is a discussion on must be a modifiable lvalue error within the C++ Programming forums, part of the General Programming Boards category; This is supposed to remove vowels from a word. However the .at doesnt work, it says the 'a' has to ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    8

    must be a modifiable lvalue error

    This is supposed to remove vowels from a word. However the .at doesnt work, it says the 'a' has to be a modifiable lvalue... what does that mean?

    Code:
    #include <string>
    #include <iostream>
    using namespace std;
      
    void vowelremover(string&);
    string word;
    int main ()
    { 
     
        cout << "Enter a word of which you want the vowels removed: ";
        cin >> word;
     
    	vowelremover(word);
     
    	cout << "The word without vowels is: " << word << endl;
    	return 0;
    
    
     }
     
     
    
    
    void vowelremover (string& enteredword)
    {
    	int posvowel;
    	int i;
    
    
     for (i == 0; i < enteredword.length(); i ++)
    	 {
    	 while (enteredword.at(i) = 'a' || enteredword.at(i) = 'e' || enteredword.at(i) = 'i' || enteredword.at(i) = 'o' || 
    		 enteredword.at(i) = 'u' || enteredword.at(i) = 'A' || enteredword.at(i) = 'E' || enteredword.at(i) = 'I' || enteredword.at(i) = 'O' || 
    		 enteredword.at(i) = 'U')
    	
    		{
    			 enteredword.erase(i, 1);
    			i == 0;
    		 }
    	 
    	 }
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    It means you're mixing up assignment operators (=) with equality operators (==) in multiple places.
    stahta01 likes this.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    double equal signs doesnt work though...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    How do they fail to work?
    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
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    "Doesn't work" is a vague and useless description of your problem. For the best assistance, post the updated code along with all warning/error messages you've received.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    Oh wow I'm stupid. The double equal signs seems to work, but when i run the program it says i'm using i without initializing it.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    That's probably because you're also mixing up with equality operators (==) with assignment operators (=).

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    Okay the error is now "Unhandled exception at 0x770b15de in FinishedLab6.exe: Microsoft C++ exception: std:ut_of_range at memory location 0x0020f7f8.." I've had this error before but can't remember how I fixed it.
    Last edited by poolofdeath; 03-26-2013 at 08:58 PM.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    Post that version of the code, please.
    laserlight likes this.

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    Code:
    #include <string>
    #include <iostream>
    using namespace std;
       
    void vowelremover(string&);
    string word;
    int main ()
    { 
      
        cout << "Enter a word of which you want the vowels removed: ";
        cin >> word;
      
        vowelremover(word);
      
        cout << "The word without vowels is: " << word << endl;
        return 0;
     
     }
      
      
     
    void vowelremover (string& enteredword)
    {
        int posvowel;
        int i;
     
     
     for (i = 0; i < enteredword.length(); i ++)
         {
         while (enteredword.at(i) == 'a' || enteredword.at(i) == 'e' || enteredword.at(i) == 'i' || enteredword.at(i) == 'o' || 
             enteredword.at(i) == 'u' || enteredword.at(i) == 'A' || enteredword.at(i) == 'E' || enteredword.at(i) == 'I' || enteredword.at(i) == 'O' || 
             enteredword.at(i) == 'U')
         
            {
                 enteredword.erase(i, 1);
                i == 0;
             }
          
         }
    }

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    What is line 36 supposed to be doing?

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    If it does find a vowel it resets i to 0 so it starts the search over because the position of the letters will be messed up.

  13. #13
    Registered User
    Join Date
    Jun 2011
    Posts
    2,371
    See post #7.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    Are you sure that it resets i to 0?
    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

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    8
    wow guys... I realize how stupid I am. So when i want something to literally equal 0 i do one and when i want it to emulate something its two equal signs? btw the code works perfectly, thanks so much for the help.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: lvalue required, pretty sure it's an lvalue
    By brandones in forum C Programming
    Replies: 18
    Last Post: 08-22-2011, 08:06 PM
  2. lvalue error
    By roaan in forum C Programming
    Replies: 6
    Last Post: 08-13-2009, 10:09 PM
  3. modifiable lvalue error
    By tsantana in forum C Programming
    Replies: 2
    Last Post: 06-10-2009, 10:58 PM
  4. non-lvalue error
    By zlb12 in forum C Programming
    Replies: 1
    Last Post: 04-17-2009, 10:43 AM
  5. lvalue error
    By paperbox005 in forum C Programming
    Replies: 4
    Last Post: 04-10-2005, 12:18 AM

Tags for this Thread


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