Writing a code

I am kind of new to C++ so I wanted help writing a program where the user enters the text and the program cout word and its number of repeated times.
Example:
Hello this is a test 1.
Hello this is a test 2.

output should be:

hello 2
this 2
is 2
a 2
test 2
1 1
2 1

--------

thnkx in advance.
Your question doesn't make sense. Please explain a bit more.
I mean I get to do a program that counts how many times the word is repeated in a text that is entered by a user. Like in the above example I want to output the word hello and beside it how many times it is repeated. The text I obtain is when the user cin>> it !!
get me now??

Hi Mennah Bennis,

Post up the code you have written so far and we can help you with it

Jimbot
Actually, you can accomplish this with vectors Mennah. I don't want to provide the code for you to do it, however I suggest you research C++ vectors. I'll just give you an idea of how to get started:

Ex.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<vector>

int main()
{
vector<string> test                   //container holding the word being pushed back
string hold;                               //word you wish to have pushed back

while(cin>>hold){
test.push_back(hold)               //pushes back what the user enters

}



Last edited on
syntax error line 10!
Topic archived. No new replies allowed.