Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you are asking how to validate multiple arguments: the command and the file.</p> <p>A simple strategy is to have function like the following:</p> <pre><code>#include &lt;fstream&gt; // Note: this is for ifstream below bool argumentsInvalid(const string&amp; command, const string &amp; command) { // Validate the command // Note: Not ideal, just being short for demo if("wc" != command &amp;&amp; "cc" != command &amp;&amp; "lc" != command) { std::cout &lt;&lt; "Invalid command" &lt;&lt; std::endl; return false; } // Validate the file // Note: This is a cheat that uses the fact that if its valid, its open. std::ifstream fileToRead(filename); if(!fileToRead) { std::cout &lt;&lt; "Invalid file: \"" &lt;&lt; filename &lt;&lt; "\"" &lt;&lt; std::endl; return false; } return true; // Note: This does rely on the ifstream destructor closing the file and would mean // opening the file twice. Simple to show here, but not ideal real code. } </code></pre> <p>If you want to evaluate ALL arguments before returning an error, insert a flag at the top of that function, like: </p> <pre><code>// To be set true if there is an error bool errorFound = false; </code></pre> <p>and change all of the returns in the conditions to:</p> <pre><code>errorFound = true; </code></pre> <p>and the final return to:</p> <pre><code>return !errorFound; </code></pre> <p>Usage:</p> <pre><code>.... if(argumentsInvalid(command, filename)) { std::cout &lt;&lt; "Could not perform command. Skipping..." &lt;&lt; std::endl; // exit or continue or whatever } // Now do your work </code></pre> <p>Note: The specific validity tests here are over simplified.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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