0

Hello,

i'm currently creating a program that allows the user to input a sentince and then the program compares each word to the array to see if there is any matches. The program also is able to sort using quicksort and other sorts. however, i am not sure how to deconstruct user inputted data and compare it to the array.

Any Help would be great :)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Kanoisa
0

I would sugegst the use of stringstreams here. Make a function that accepts a string, build a stringstream from that then take all the words out one at a time say into a vector. then you can use the algorithm functions to search the vector.

vector<string> SplitString(const string& inputStr)
{
   ostringstream oss(inputStr); //constructs oss to have the contents of inputStr
   string temp; //place holder for each word during extraction
   vector<string> split;
   
   //now we loop 
   while(oss>>temp)//while there are words in the oss, extract one
   {
       split.push_back(temp); //append the word to the vector
   }

   return split;

}

After a function like this one you would be free to search the vector using whatever sort and finding algorithms you wanted.

Just be aware i didnt check this code but its the idea of what your looking for.

Edited by Kanoisa: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.