Word comparison - Vectors /Getopt

Please Help!!!

My understanding of getopt is very limited.
I do however realise that argv[0] is the exe file, argv[1] is the option, argv[2] is the word to compare and argv[3] is the dictionary or document I want to search(file .txt).
I'm trying to set a pointer to the dictionary and then iterate through it to see if there is a match with the argv[2] (input word) to the text file, and if there is a match out put the argv[2] word.
Below is my current code that has errors
main.cpp:61: error: no match for 'operator==' in 'list == *(argv + 12u)'
main.cpp:64: error: no match for 'operator*' in '*list'
Any help would be greatly appreciated.

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
59
60
61
62
63
64
/
#include <cstdlib>
#include <unistd.h>
#include <vector>
#include <iostream>
#include <string>
#include <iterator>

using namespace std;

int main(int argc, char** argv) {

    enum {
        WHOLE, PREFIX, SUFFIX, ANYWHERE, EMBEDDED
    } mode = WHOLE;
    bool jumble = false;
    bool ignore_case = false;
    bool invert = false;
    string length = "0,0";
    int c;
    string input;
    vector <string> list;
    vector <string>::iterator i;

    while ((c = getopt(argc, argv, ":wpsaejivn:")) != -1) {
        switch (c) {
            case 'w': mode = WHOLE;
                break;
            case 'p': mode = PREFIX;
                break;
            case 's': mode = SUFFIX;
                break;
            case 'a': mode = ANYWHERE;
                break;
            case 'e': mode = EMBEDDED;
                break;
            case 'j': jumble = true;
                break;
            case 'i': ignore_case = true;
                break;
            case 'v': invert = true;
                break;
            case 'n': length = optarg;
                break;
            default: WHOLE;
                break;
        }
    }
    argc -= optind;
    argv += optind;

    switch (mode) {
        case WHOLE:
            while(argc != -1){
                list == argv[3];
                for(i == list.begin(); i != list.end(); i++)
                if(argv[1] == argv[3]){
                    cout << *list << endl;
                }else cout << "Did not work again" << endl;
            }                                  
    }
    return 0;
}
What are you trying to do with the following statement?
list == argv[3];
That appears to be doing a pointless comparison of the list container with the third argument. No such comparison is supported by the list container; hence the first diagnostic.

Likewise for the following statement:
cout << *list << endl;
You are treating list as a pointer. It's not, therefore the second diagnostic. Also, the << operator is not defined for the list container.

for(i == list.begin();
You're confusing the assignment operator = with the equality operator ==.
You want to assign the iterator i to value return from begin(), not compare it.
Yes, I see what you mean.
The idea was to get list to point to the contents of argv[3] (text file or document) then loop through that to see if there was a match with argv[2] (word) which I currently have as argv[1] my mistake.
Thank you for responding Abstraction Anon.
Would it be best practice to open the dictionary / text file within the code (using infile.open(.txt))or open from the command prompt?
Topic archived. No new replies allowed.