Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:45:41+00:00 2026-06-09T20:45:41+00:00

thanks for reading this question. Basically I am trying to do a code that

  • 0

thanks for reading this question.

Basically I am trying to do a code that can achieve the following:

User will be shown a list of details like this

Terminal View:

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: 

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.

How do I detect user input is ‘remove userid’
or ‘add userid’ and then get the userid

e.g add 86
then he add 90

then he decided to remove 90

how do the string keep up with it

Below is my code:

do
{
cout << "Current Selected Participant : " << participant << endl; 
cout << "" << endl;

do
{
if(counter>0)
{
//so it wont print twice
cout << "Usage: " << endl; 
cout << "Type exit to return to main menu" << endl;
cout << "Type remove userid to remove participant" << endl;
cout << "Type add userid to add participant" << endl;
cout << "" << endl;
cout << "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 << "There no participant " << buffer << " in the list " << 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);

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

then get the user id which is seperate by a whitespace.

Next is how to remove if i store in a string set and how to push new value in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:45:43+00:00Added an answer on June 9, 2026 at 8:45 pm

    Don’t store it in a string. Store it in a collection that allows easy insertion and removal, like a std::set<int>. When the process has finished you can convert the set to whichever representation you feel you need.

    Here’s a very simple example (not checked to see if it compiles and runs; that’s left as an exercise for the reader!)

    void handle_command(const std::string& command, std::set<std::string>& userids)
    {
        if (command.substr(0, 4) == "add ")
        {
            std::string uid = command.substr(4);
    
            if (userids.find(uid) == userids.end())
                userids.insert(uid);
            else
                std::cout << "Uid already added" << std::endl;
    
            return;
        }
        else
            throw std::exception("Unsupported command, etc");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thank you for reading this Question. CODE BELOW I'm trying to get a jsp
Thanks in Advance for reading and answer this question. I got button in asp
Thanks for reading this. I'm trying to do this lab from programarcadegames.com where you
Hello I was reading this question, I got confused with how if we can
Thanks for reading this. I have no idea why this is throwing a NullReferenceException
Firs of all thanks for reading this. I'm having trouble updating the progress from
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
I have code listed here: Threading and Sockets . The answer to that question
I am coming back from after reading this c-faq question I am totaly confused
This is a follow-up of this question: Ada: reading from a file . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.