Words in array

Hello I am a student in need of help. The problem I need solved is this:
Input 20 words and then output the words and count how many times each word has been input. For example if I input apple 5 times and banana 3 times and some other words so it adds upp to 20 it should output: apple=5 banana=3 kiwi=1 orange=1 etc..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
    string ord[21];
    for(int i=1; i<21; i++)
    {
        system("CLS");
        cout<<"Enter word number ["<<i<<"] :";
        cin>>ord[i];

    }
    for(int i=1; i<21; i++)
    {
        int count=1;
        for(int x=i+1; x<21; x++)
        {
           if(ord[x]==ord[i])
           {
             count++;
           }
        }
        cout<<ord[i]<<"="<<count<<endl;
    }
}

Here is my code so far it works to some extent but if you run it you can see that it says a word has been repeated then it shows the word again but this time it says it's been repeated one less time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <algorithm>

int main()
{
    std::array<std::string, 20> input;
    std::vector<std::string> words;
    
    std::cout << "Enter 20 words:\n\n";
    
    for (std::string &s : input)
    {
        std::cin >> s;
        if (std::find(words.cbegin(), words.cend(), s) == words.cend())
        {
            words.push_back(s);
        }
    }
    
    std::cout << "\n=======================\n\n";
    
    for (const std::string &s : words)
    {
        std::cout << s << " = " << std::count(input.cbegin(), input.cend(), s) << '\n';
    }

    std::cin.ignore();
    std::cin.get();
    
    return 0;
}
Last edited on
It gives me an error and says that its not part of the library, do I have to download a compiler or something? Here's the error.
#ifndef __GXX_EXPERIMENTAL_CXX0X__
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif
What compiler do you have? Or IDE?

Can you enable C++11 (or C++14) on your compiler? Is it up to date? Do you know how?

You have to compile my code with C++11 at least.
Last edited on
By the way, here's some sample output with my code.

Enter 20 words:

Apple
Strawberry
Orange
Blueberry
Pineapple
Pear
Apple
Apple
Orange
Strawberry
Blueberry
Pineapple
Orange
Orange
Apple
Orange
Kiwi
Kiwi
Orange
Apple

=======================

Apple = 5
Strawberry = 2
Orange = 6
Blueberry = 2
Pineapple = 2
Pear = 1
Kiwi = 2
Yes I have enablede support for c++11 thank you for the help!
Topic archived. No new replies allowed.