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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:40:51+00:00 2026-06-11T20:40:51+00:00

Supposing stringstream contains James is 4 , I can write something like getline (stream,

  • 0

Supposing stringstream contains James is 4 , I can write something like getline (stream, stringjames, ' ') to get the individual words, but is there any way to know that I’ve hit the end of the line?

Bonus Question!
Case 1: James is 4
Case 2: James is four

If I were iterating through the words in a stringstream, and I expect to receive an int val of 4, but instead I received a string, what would be the best way to check this?

  • 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-11T20:40:52+00:00Added an answer on June 11, 2026 at 8:40 pm

    You check the return value to see if it evaluates true or false:

    if (getline(stream, stringjames, ' '))
        // do stuff
    else
        // fail
    

    As for the “bonus question” you can also do the same thing when extracting ints and things from streams. The return value of operator>> will evaluate to true if the read was successful, and false if there was an error (such as there being letters instead of numbers):

    int intval;
    
    if (stream >> intval)
        // int read, process
    else if (stream.eof())
        // end-of-stream reached
    else
        // int failed to read but there is still stuff left in the stream
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supposing I'm having the constants 3,5,6,9,10. How can I detect how to write $n,
Supposing I have a 2 dimensional array which was created with something like this,
Supposing I've got multiple div's with the same class, I could do something like
Supposing to have something like this: #include <map> int main(){ std::map<int,int> m; m[1] =
Supposing I have 3 tables: Users, Roles and UserRoles. I can fetch the user_roles
Supposing I have this: foo bar 1 and foo bar 2 How can I
Supposing I have the following script <div id=something> <?php // execute a loop ?>
Using PostgreSQL, supposing a table like the following: 12184 | 4 | 83 12183
When should I use stringstream instead of string::append() ? Supposing I'm going to catenate
Supposing I'm setting a background image for a web page in CSS like this:

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.