Can someone tell me how to write code for a function that adds "!" to the end of each STRING object in a list. This is what I have:
Will this work?Code:void exclamation(Node* head) { const string s = "!"; string list +=s; cout << list; }
Can someone tell me how to write code for a function that adds "!" to the end of each STRING object in a list. This is what I have:
Will this work?Code:void exclamation(Node* head) { const string s = "!"; string list +=s; cout << list; }
I think it will.
but I think you can only do this:
Code:List = List + "!";
Why drink and drive when you can smoke and fly?
No - you haven't done anything at all to any string pointed to by head.
All you are doing here is creating 2 strings, one called s and one called list, both containing !, and then printing ! to the screen.
You need to find a way to use that pointer to walk through the list of strings one element at a time, adding '!' to each one. (You don't even need that new string s. The right operand of += can be a char.)
What about using strcat()?
Code:while (head != NULL) { head->str += "!"; head = head->next; }