When i dereference the pointers, there is no value showing but when i don't dereference the pointers it shows the addresses. I don't understand why it wont show the values i am putting in. Please help.
int main()
{
cout<<"Welcome to Mad-Lib.\n\n";
cout<<"Answer the following questions to help create a new story.\n";
string* pName = &ask_text("Please enter a name: ");
string* pNoun = &ask_text("Please enter a plural noun: ");
int number = ask_number("Please enter a number: ");
string* pBody_part = &ask_text("Please enter a bodypart: ");
string* pVerb = &ask_text("Please enter a verb: ");
void tell_story(string* const pName, string* const pNoun, int number,
string* const pBody_part, string* const pVerb)
{
cout<<"\nHere's your story:\n";
cout<<"The famous explorer ";
cout<<*pName;
cout<<" had nearly given up a life-long quest to find\n";
cout<<"The Lost City of ";
cout<<*pNoun;
cout<<" when one day, the ";
cout<<*pNoun;
cout<<" found the explorer\n";
cout<<"Surrounded by ";
cout<<number;
cout<<" "<<*pNoun;
cout<<", a tear came down to ";
cout<<*pName<<"'s ";
cout<<*pBody_part<<".\n";
cout<<"After all this time, the quest was finally over. ";
cout<<"And then, the ";
cout<<*pNoun<<"\n";
cout<<"promptly devoured ";
cout<<*pName<<". ";
cout<<"The moral of the story? Becareful what you ";
cout<<*pVerb;
cout<<" for.";
}
Your program is invalid and I do not understand why you are using pointers to string instead of strings themself. For example in this statement
string* pName = &ask_text("Please enter a name: ");
you are assigning pName the address of a temporary object returned by the function that will be deleted at once after executing the statement. So the program behavior is undefined.