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 9171911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:13:40+00:00 2026-06-17T16:13:40+00:00

I am working on a program that allows a user to add a department

  • 0

I am working on a program that allows a user to add a “department” to school records. The departments are stored as structs like this:

struct Department{

  string ID;
  string name;
};

To add a new department to the records, the user must enter a command formatted like this:

D [5 digit department ID number] [Department name] 

The [Department name] field is a string that extends until the user presses enter. It can thus have any number of spaces (e.g. “Anthropology” or “Computer Science and Engineering”).

When the user inputs the command string correctly (obtained with getline), it is passed to a function that should extract the relevant information and store the record:

void AddDepartment(string command){

  Department newDept;
  string discard;     //To ignore the letter "D" at the beginning of the command 

  istringstream iss;
  iss.str(command);

  iss >> discard >> newDept.ID >> ??? //What to do about newDept.name? 

  allDepartments.push_back(newDept);

}

Unfortunately, I can’t figure out how to make this approach work. I need a way (if there is one) to finish reading iss.str while ignoring white spaces. I setting the noskipws flag, but the name field in the new record was empty when I tested it:

... 
iss >> discard >> newDept.ID >> noskipws >> newDept.name; 
...

I suppose I am missing something about termination conditions/characters. How else can I create the functionality I want…maybe something with get or even a loop?

  • 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-17T16:13:40+00:00Added an answer on June 17, 2026 at 4:13 pm

    I would skip leading whitespace and then read the rest of the line

    iss >> discard >> newDept.ID >> ws;
    std::getline(iss, newDept.name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon. I'm working on a drawing program that allows the user to drag
I have a program where i use a modal popup that allows the user
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
I have created the output for a program that allows a user to input
I'm working on a PHP page that allows the user to reset their password.
I have a program that's creating a secure directory for user output. This is
I am working on a scrabble program that generates 7 letters, then allows the
I am working on a PHP web application that allows the user to edit
I've been trying to program an android that takes allows the user to pull
I am working on a program that would allow the user to build digital

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.