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 :)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.