Hello,
I just started learning strings and dont even know how to properly execute simple part of the program that splits phrase of two words with one space in between into 2 separate strings. I realize that substr() need to be used, but words may varie in length so I have to make it initialize first string any length before first space and second string after the space.
For example: "computer science"
into first string "computer" second string "science"
Here's whats being asked of me:
call a function makewords() which receives three parameters: a string which holds the original phrase and two strings to hold the two words. The function will break the string stored in the first parameter (the original sentence) into two words and then store it in one of the parameters.
Note: The function can assume there is exactly one space between the words in the sentence.
For example, if the original sentence holds: "computer science", then the two words are "computer" and "scienceā.
You should use member functions such as find and substr to help you with this function
Your function, makewords(), should then check if the 2 new strings are equal to each other, and print the appropriate message saying whether or not they are equal.
print out the two words and their sizes.
Here's my starting piece of code:
Any help is appreciated!
I just started learning strings and dont even know how to properly execute simple part of the program that splits phrase of two words with one space in between into 2 separate strings. I realize that substr() need to be used, but words may varie in length so I have to make it initialize first string any length before first space and second string after the space.
For example: "computer science"
into first string "computer" second string "science"
Here's whats being asked of me:
call a function makewords() which receives three parameters: a string which holds the original phrase and two strings to hold the two words. The function will break the string stored in the first parameter (the original sentence) into two words and then store it in one of the parameters.
Note: The function can assume there is exactly one space between the words in the sentence.
For example, if the original sentence holds: "computer science", then the two words are "computer" and "scienceā.
You should use member functions such as find and substr to help you with this function
Your function, makewords(), should then check if the 2 new strings are equal to each other, and print the appropriate message saying whether or not they are equal.
print out the two words and their sizes.
Here's my starting piece of code:
Code:
void makewords(string ,string ,string){ string phrase; getline(cin,phrase); string first, second; system("pause"); }
Any help is appreciated!
Comment