Thread: converting string to char; storing info in a class

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    14

    converting string to char; storing info in a class

    I'm having a problem with converting a string to a char. ; Also I keep getting errors in regards to storing info in a object that will be stored in a class data member. Can anyone help?

    Code:
    #include "song.h"
    #include <cstring>
    
    using namespace std;
    
    //char size[50];
    	
    	
    string Song::getTitle() 
    	{ 
    		return title;
    	}
    
    string Song::getArtname()
    	{
    		return artname;
    	}
    	
    string Song::getAlbum()
    	{
    		return album;
    	}
    	
    string Song::setTitle()
    	{
    		return title;
    	}
    	
    string Song::setArtname()
    	{
    		return artname;
    	}
    
    string Song::setAlbum()
    	{
    		return album;
    	}
    
    bool Song::operator == (Song track)
    	{ 
    	
    	
    		char* temp1 = &title; 
    		char* temp2 = &artname;
    		char* temp3= &album;
    		
    		if(strcmp(title, track.title) == 0 && strcmp(artname, track.artname) == 0 && strcmp(album, track.album) == 0)
    				return true;
    					else
    						return false;
    		
    	} // the end of the function
    	
    	
    bool Song::operator > (Song track)
    	{
    			char* temp4 = &title[0];
    			char* temp5 = &artname[0];
    			char* temp6 = &album[0];
    			
    				if (strcmp(title, track.title) > 0 && strcmp(artname, track.artname) > 0 && strcmp(album, track.album) > 0)
    					return true;
    						else 
    							return false;
    	}
    Code:
    if( choice == Add) {
    		 cout<<"Enter the name of your song: "<<endl;
    		 
    		 cin>>track[count].setTitle();
    		 
    		 cout<<"Enter the Artist's name: "<<endl;
    		 
    		 cin>>track[count].setArtname();
    		 
    		 cout<<"Enter the Album's name: "<<endl;
    		 
    		 cin>>track[count].setAlbum();
    I keep getting errors that say : Could not convert setTitle to bool. ???

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    your setTitle() function is completely the same as getTitle()..bit of a waste

    it doesn't set anything..
    i assume you declared title artname and album members..because I couldn't find them in the above code...

    cin>>track[count].setTitle();

    another is that ^^
    you can't assign to an rvalue...you need to return a reference to the calling function..

    I still don't know..how a compiler detects an rvalue
    Last edited by Eman; 02-07-2011 at 05:16 PM.
    You ended that sentence with a preposition...Bastard!

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    14
    thanks for the response. the members are declared in my spec file. How do I perform the referencing you speak of?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

Tags for this Thread