我的理解getopt
非常有限。但是,我确实意识到这argv[0]
是 exe 文件,argv[1]
是选项,argv[2]
是要比较的词,并且argv[3]
是我要搜索的字典或文档(文件.txt
)。
我正在尝试设置一个指向字典的指针,然后遍历它以查看是否与argv[2]
文本文件的(输入单词)匹配,以及是否匹配输出该argv[2]
单词。以下是我当前有错误的代码:
main.cpp:61: error: no match for 'operator==' in 'list == *(argv + 12u)'
main.cpp:64: error: no match for 'operator*' in '*list'
任何帮助将不胜感激。
#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;
}