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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:21:28+00:00 2026-05-20T08:21:28+00:00

I just starting out in C++ and I’ve reached a problem in some practice

  • 0

I just starting out in C++ and I’ve reached a problem in some practice questions that I can’t quite figure out. I need to be able to read a line from the console in the form of:

N A B C... etc.

Where N is a number, and the following input will be of different types and different amounts based on what N is.

My approach would be to read N and then ask for the different inputs based on what N is. But I have to accept all the input on a single line, and I haven’t been able to get any form of input to terminate after a single space character. So is there anyway I could move on to the next statement after receiving a single number, and a space character? Or is there a better way to go about this problem? Thanks is advance.

EDIT:

Okay I think I’ve figured it out but I don’t completely understand it, so I’ll have to look into istringstream. Here’s what I have.

vector<string> words;

string token, text;
getline(cin, text);

istringstream iss(text);

while ( getline(iss, token, ' ') ) {

    words.push_back(token);

}

Is this a good way to do it, or should I be taking another approach? And if anyone could, can you explain these lines for me?

while ( getline(iss, token, ' ') )

I guess this returns true when it reaches a space, while filling up token with all previous characters?

And this one confuses me.

getline(cin, text);
  • 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-05-20T08:21:29+00:00Added an answer on May 20, 2026 at 8:21 am

    You should read in the entire line at once (as requested) and then depending on N, your code should check the rest of the input to make sure it is properly formatted or print out an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out with the whole ajax thing and I need some help.
I'm just starting out with WiX as I need to be able to automate
I'm just starting out in WinPhone development and can't figure out how to set
I'm just starting out with Python, and have found out that I can import
I'm just starting out with iphone development and ran across some example code that
Just starting out in Objective-C, so I'm curious as to how some apps that
I'm just starting out in JSF, looks awesome, but I can't seem to figure
Just starting out, this should be a simple one but I haven't been able
I am just starting out with Silverlight (2 RC0) and can’t seem to get
Just starting out with an iPhone application using xcode 4.2. I understand that it

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.