CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    17

    Resolved This is really lame...

    Take a look at my code....
    Code:
    /*******************************************
    FAMILY PROGRAM
    
    PROGRAMMED BY GREG MARTIN
    *******************************************/
    
    /*******************************************
    PREPROCESSOR DIRECTIVES
    *******************************************/
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    
    /*******************************************
    GLOBAL DECLARATIONS
    *******************************************/
    enum moods {md_normal, md_happy, md_ecstatic, md_sad, md_mad, md_angry};
    enum gender {gn_male, gn_female};
    
    /*******************************************
    PERSON CLASS DECLARATION
    *******************************************/
    class Person{
    public:
    	//attributes
    	string myFullName;
    	string myTitle;
    	int myAge;
    	moods myCurrentMood;
    	gender myGender;
    
    	//method prototypes
    	int askAge() {return myAge;};
    	int askMood() {return myCurrentMood;};
    	int askGender() {return myGender;};
    	string askTitle() {return myTitle;};
    	string askName() {return myFullName;};
    	string speakToPerson(string targetPerson, string speechString);
    	void speakToSelf(string speechString);
    };
    
    /*******************************************
    MAIN FUNCTION
    *******************************************/
    int main(){
    	//local variables
    	Person mom;
    
    	//set some attributes of the person we just created
    	mom.myFullName = "Kellie Johnson";
    	mom.myGender = gn_female;
    	mom.myTitle = "Mother";
    	mom.myAge = 38;
    
    	//output some information about the person we just created
    	cout << "We created a person." << endl;
    	cout << "This person's name is " << mom.myFullName << endl;
    	
    	return 0;
    }
    This program isn't for anything special, I'm just bored.

    The last cout statement in the main function is what my compiler is complaining about. Without it, it compiles nicely. With that statement in there, I get this error:

    binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

    And then there are a bunch of nonsense function looking things after it but it only does this when the last cout statement in the main fuction is either commented or removed. Why is this? Does it have anything to do with my class declaration?

    EDIT: NVM I FIXED THE PROBLEM.
    Last edited by Ejaz; March 8th, 2006 at 06:16 AM. Reason: Code tag added

  2. #2
    Join Date
    Mar 2006
    Location
    You can guess, but it'll be wrong
    Posts
    12

    Unhappy Re: This is really lame...

    Your program just won't compile due to its lack of string header file. I don't understand why it is eliminated for a problem's proposal.
    My mom told me that private keyword should be used for local class variables.
    Last edited by Emiene; March 8th, 2006 at 01:54 AM.
    Emiene Vous

  3. #3
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: This is really lame...

    use this code
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    
    enum moods {md_normal, md_happy, md_ecstatic, md_sad, md_mad, md_angry};
    enum gender {gn_male, gn_female};
    
    class Person
    {
    public:
    	char *myFullName;
    	string myTitle;
    	int myAge;
    	moods myCurrentMood;
    	gender myGender;
    	int askAge() {return myAge;};
    	int askMood() {return myCurrentMood;};
    	int askGender() {return myGender;};
    	string askTitle() {return myTitle;};
    	string askName() {return myFullName;};
    	string speakToPerson(string targetPerson, string speechString);
    	void speakToSelf(string speechString);
    };
    
    int main()
    {
    	Person mom;
    	mom.myFullName ="Kellie Johnson";
    	mom.myGender = gn_female;
    	mom.myTitle = "Mother";
    	mom.myAge = 38;
    	cout << "We created a person." ;
    	cout << endl;
    	cout << "This person's name is ";
    	cout << mom.myFullName;
    	cout << endl;
    	return 0;
    }
    If I Helped You, "Rate This Post"

    Thanks
    Guna

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured