Could someone check this vector for me please because I am not sure | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Could someone check this vector for me please because I am not sure

-Create a function called createKeywords to receive a text(string) and will return a vector with keywords. For more advanced feature create a list of words which you do not want to be in your keywords. For example, when, where, what, I, you, they (You do not have to do advanced feature). I was wondering how to make the vector of list not in the keywords.This is what I have so far int createKeywords (string text) { vector <string> keywords { keywords.push_back ("when"); keywords.push_back ("where "); keywords.push_back ("what"); keywords.push_back ("I"); keywords.push_back ("you"); keywords.push_back ("they"); } for (int i=0; i<keywords.size(); i++) { cout <<keywords[i] << endl; } return keywords; } Thanks in advance

1st Dec 2020, 5:48 AM
Skylar Yang
Skylar Yang - avatar
5 Answers
+ 3
Here you go, it is the solution for the first part of the problem, but I am leaving the second for you to figure out on your own. 👇 https://code.sololearn.com/cbFRBOT6k9zw/?ref=app
1st Dec 2020, 8:34 AM
Arsenic
Arsenic - avatar
+ 2
Skylar Yang what are you doing here ? 🧐 Can you explain what exactly are you trying to achive in the above(second) code snippet ? P.S. if you want, I can also provide you with the code but I think it would be better for you if you try to implement it on your own.🙂
1st Dec 2020, 8:14 AM
Arsenic
Arsenic - avatar
+ 1
Here's what you have to do :- 1) Travers the input string (text in this case) word by word { ending of a word is marked by a whitespace } 2) check wether the keyword scanned just now is to be put in the final list or not 3) if yes then store the scanned words in a vector. 4) Continue scanning the text for words untill you don't reach the end what you are doing right now is storing the "not required" keywords in a vector and returning that after printing. try the above approach and then show what you have made.
1st Dec 2020, 6:05 AM
Arsenic
Arsenic - avatar
+ 1
void createKeywords (string , vector <string>) { string newString; while (line[index]) newString+=(line[index++]) vector.push_back(newString) newString =""; } Is it something like this? Arsenic
1st Dec 2020, 7:09 AM
Skylar Yang
Skylar Yang - avatar
0
Thank you Arsenic. Let me work on it.
2nd Dec 2020, 1:07 PM
Skylar Yang
Skylar Yang - avatar