ٍٍSet c++ prints word without repetition what is wrong ?

I want to take from user number of word and prints word without repetition


I know there is syntic wrong but i cant find it plaese help ..


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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
   #include <iostream>

    #include <string>

    #include <set>

    using namespace std;

    int main()
    {
    string word,temp;

    int w;

    cout << "How many words? ";

    cin >> w;
 
    set<string> words;

    set<string>::value_compare mycomp = words.value_comp();

    while (w > 0)
    {

    cout << "Word # " << w <<":";
 
    cin >> word; 

    word=temp;

    mycomp(word,temp);

    if (word !=temp);

    words.insert(word);  // i think the problem in compare way

     w--;

      } 
    cout << "Words:\n";


    for(set<string>::const_iterator it = words.begin();

    it != words.end(); ++it)

    {

    cout << *it << '\n';

     }

     system("pause");

     return 0;

      }
Line 30 //over writing the string
Line 34 // semicolon after if statement
Some comments:
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
#include <iostream> // Fine
#include <string>   // Fine
#include <set>      // Fine
using namespace std; // Err...whatever

int main() // Fine
{
    string word //, Fine
        //temp  // Not needed
        ;
    int w; // Could use a more descriptive name, but whatever
    cout << "How many words? "; // Fine
    cin >> w; // Fine
    
    set<string> words; // Fine
    //set<string>::value_compare mycomp = words.value_comp(); // What?
    
    while (w > 0) // Going in reverse order? Whatever
    {
        cout << "Word # " << w << ": "; // Fine
        cin >> word; // Fine
        //mycomp(word, temp); // Huh?
        //if (word != temp);  // What?
        words.insert(word); // std::set automatically takes care of the compare for you
        w--; // Fine
    }
    // Everything after this is fine...
    cout << "Words:\n";
    for (set<string>::const_iterator it = words.begin(); it != words.end(); ++it)
        cout << *it << '\n';
    //system("pause") // ...except I wouldn't use this.
    return 0;
}
thanks
Topic archived. No new replies allowed.