Note that there are some explanatory texts on larger screens.

plurals
  1. POstring operations and odd results
    primarykey
    data
    text
    <p>first post so my apologies if I break protocol.</p> <p>I'm working on a silly program for school and I have the following code. <code></p> <pre><code>cout &lt;&lt; "//Dictionary Program//\n\n"; cout &lt;&lt; "Enter a command:\n's' - to search for a pattern at the beginning\n"; cout &lt;&lt; "'e' - to search for a pattern at the end\n"; cout &lt;&lt; "'c' - to search for a pattern anywhere in the word\n"; //Gather user input. cout &lt;&lt; "Please enter a command ('q' to quit): "; cin &gt;&gt; userCommand; cmdCheck = userCommand.find("secq"); while(cmdCheck &lt; 0 || userCommand.length() &gt; 1){ cout &lt;&lt; "Please enter a valid command\n"; cin &gt;&gt; userCommand; cmdCheck = userCommand.find("secq"); } </code></pre> <p></code></p> <p>This is driving a menu and I am trying to validate the input. It should be one letter, and one of the following "secq"</p> <ol> <li><p>I am having a terrible time with the string.find() in the immediate window. I end up with CXX0047: Error: argument list does not match a function. Which I don't understand at all because I am using it elsewhere.</p></li> <li><p>The while condition is not being nice to me. When I give the program a "v" it ends up inside the block like it should, but then I give it an "s" where the cmdCheck should evaluate to 0, but it gives a -1 and stays inside the block.</p></li> <li><p>Lastly, I coded around another error with the cmdCheck but I had that in the while condition and it was not working either. <code>while(userCommand.find("secq") &lt; 0 ...</code></p></li> </ol> <p>My inital thought was a problem with the input buffer but when I look at the userCmd variable in the Locals window I have a character array of size 1. There is only the letter and no junk from the buffer (as far as I can tell)</p> <p>I know I could just tie a bunch of || together with each command but this is a bit more elegant in my opinion. I looked at my final last year and my conditionals were ugly. It's more of a matter of principle at this point.</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.
 

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