Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ How do I do a loop that add in new value and can delete existing value
    primarykey
    data
    text
    <p>thanks for reading this question.</p> <p>Basically I am trying to do a code that can achieve the following:</p> <p>User will be shown a list of details like this</p> <p>Terminal View:</p> <pre><code>Please select the department you want to add participant: 1. Admin 2. HR 3. Normal 4. Back to Main Menu Selection: 3 normal's Department UserID: 85 [ Name: Andrew, Department: normal ] UserID: 86 [ Name: Jacky, Department: normal ] UserID: 90 [ Name: Baoky, Department: normal ] Current Selected Participant : Usage: Type exit to return to main menu Type remove userid to remove participant Type add userid to add participant Selection: </code></pre> <p>Question is : I want to be able to like let user add as many participant as he want until he decide to 'exit' to main menu, but how do i store it in a string participant.</p> <p>How do I detect user input is 'remove userid' or 'add userid' and then get the userid</p> <p>e.g add 86 then he add 90</p> <p>then he decided to remove 90</p> <p>how do the string keep up with it</p> <p>Below is my code:</p> <pre><code>do { cout &lt;&lt; "Current Selected Participant : " &lt;&lt; participant &lt;&lt; endl; cout &lt;&lt; "" &lt;&lt; endl; do { if(counter&gt;0) { //so it wont print twice cout &lt;&lt; "Usage: " &lt;&lt; endl; cout &lt;&lt; "Type exit to return to main menu" &lt;&lt; endl; cout &lt;&lt; "Type remove userid to remove participant" &lt;&lt; endl; cout &lt;&lt; "Type add userid to add participant" &lt;&lt; endl; cout &lt;&lt; "" &lt;&lt; endl; cout &lt;&lt; "Selection: "; } getline(cin,buffer); counter++; }while(buffer==""); if(buffer.find("remove")) { str2 = "remove "; buffer.replace(buffer.find(str2),str2.length(),""); if(participant.find(buffer)) { //see if buffer is in participant list buffer = buffer + ","; participant.replace(participant.find(buffer),buffer.length(),""); } else { cout &lt;&lt; "There no participant " &lt;&lt; buffer &lt;&lt; " in the list " &lt;&lt; endl; } }//buffer find remove keyword if(buffer=="exit") { done=true; } else { sendToServer = "check_account#"+buffer; write (clientFd, sendToServer.c_str(), strlen (sendToServer.c_str()) + 1); //see if server return found or not found readFromServer = readServer (clientFd); if(readFromServer=="found") { //add to participant list participant += buffer; participant += ","; } }//end if not exit }while(done!=true); </code></pre> <p>Some users suggest i store in a string set, how do i store in a string set, and how do i make terminal able recognize keyword like 'remove' and 'add' in the selection</p> <p>then get the user id which is seperate by a whitespace.</p> <p>Next is how to remove if i store in a string set and how to push new value in.</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.
 

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