# Find The Longest Word in a Paragraph

Page 1 of 1

## 1 Replies - 10155 Views - Last Post: 23 February 2007 - 06:38 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=24311&amp;s=0c7e8525e371cc63469219d14f72db03&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pavani2006

Reputation: 2
• Posts: 15
• Joined: 22-February 07

# Find The Longest Word in a Paragraph

Posted 22 February 2007 - 07:57 PM

Would like code in C
```#include <iostream>
#include <sstream>
#include <string>
#include <vector>  // for the vector option

using namespace std;

int main()
{
string sentence, word;
// create a string vector to hold the words
vector<string> sV;

cout << "Enter a sentence: ";
getline(cin, sentence);

// put the sentence into a stream
istringstream instr(sentence);

// the >> operator separates the stream at a whitespace
while (instr >> word)
{
cout << word << endl;
// optionally store each word in a string vector
// could use an array, but a vector is easier
sV.push_back(word);
}

// now let's look at the vector
cout << "You typed " << sV.size() << " words:\n";
for(int k = 0; k < sV.size(); k++)
{
cout << sV[k] << endl;
}

cin.sync();  // purge enter
cin.get();   // console wait
return 0;
}
```

~Admin Edit: Added [code] tags, removed all caps from title, fixed spelling mistakes in title

Is This A Good Question/Topic? 0

## Replies To: Find The Longest Word in a Paragraph

### #2 qdoom

Reputation: 1
• Posts: 82
• Joined: 31-August 06

## Re: Find The Longest Word in a Paragraph

Posted 23 February 2007 - 06:38 AM

```word.size()