Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto not being recognised by the compiler, what would be the best replacement?
    primarykey
    data
    text
    <p>So I have wrote a program that uses auto however the compiler doesn't seem to recognize it, probably it is an earlier compiler.</p> <p>I was wondering for my code, what are suitable variables to fix my code so that I do not need to use the auto keyword? I'm thinking a pointer to a string? or a string iterator, though I am not sure. </p> <pre><code> #include &lt;cstdlib&gt; #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;unistd.h&gt; #include &lt;algorithm&gt; using namespace std; int main(int argc, char* argv[]) { enum MODE { WHOLE, PREFIX, SUFFIX, ANYWHERE, EMBEDDED } mode = WHOLE; bool reverse_match = false; int c; while ((c = getopt(argc, argv, ":wpsaev")) != -1) { switch (c) { case 'w': // pattern matches whole word mode = WHOLE; break; case 'p': // pattern matches prefix mode = PREFIX; break; case 'a': // pattern matches anywhere mode = ANYWHERE; break; case 's': // pattern matches suffix mode = SUFFIX; break; case 'e': // pattern matches anywhere mode = EMBEDDED; break; case 'v': // reverse sense of match reverse_match = true; break; } } argc -= optind; argv += optind; string pattern = argv[0]; string word; int matches = 0; while (cin &gt;&gt; word) { switch (mode) { case WHOLE: if (reverse_match) { if (pattern != word) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } } else if (pattern == word) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } break; case PREFIX: if (pattern.size() &lt;= word.size()) { auto res = mismatch(pattern.begin(), pattern.end(), word.begin()); if (reverse_match) { if (res.first != word.end()) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } } else if (res.first == word.end()) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } } break; case ANYWHERE: if (reverse_match) { if (!word.find(pattern) != string::npos) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } } else if (word.find(pattern) != string::npos) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } break; case SUFFIX: if (pattern.size() &lt;= word.size()) { auto res = mismatch(pattern.rbegin(), pattern.rend(), word.rbegin()); if (reverse_match) { if (res.first != word.rend()) { matches = +1; cout &lt;&lt; word &lt;&lt; endl; } } else if (res.first == word.rend()) { matches = +1; cout &lt;&lt; word &lt;&lt; endl; } } break; case EMBEDDED: if (reverse_match) { if (!pattern.find(word) != string::npos) { matches += 1; cout &lt;&lt; word &lt;&lt; endl;} } else if (pattern.find(word) != string::npos) { matches += 1; cout &lt;&lt; word &lt;&lt; endl; } break; } } return (matches == 0) ? 1 : 0; } </code></pre> <p>Thanks in advance!</p> <p>Errors I get:</p> <pre><code>main.cpp:70:26: error: 'res' does not name a type main.cpp:73:29: error: 'res' was not declared in this scope main.cpp:77:32: error: 'res' was not declared in this scope main.cpp:97:26: error: 'res' does not name a type main.cpp:100:29: error: 'res' was not declared in this scope main.cpp:104:32: error: 'res' was not declared in this scope </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload