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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:41:19+00:00 2026-06-04T20:41:19+00:00

I have a vector of strings that contain numbers, words, spaces, and even weird

  • 0

I have a vector of strings that contain numbers, words, spaces, and even weird characters like quotation marks. I am trying to read it all in using a stringstream so I can separate the doubles from strings.

When I do this:

stringstream contains

4165 This package contains 12 1/2" Screws

Code:

stringstream >> mydouble 
stringstream >> mystring

mydouble contains

4165

Then the only thing that gets read into mystring is

This package contains 12 1/2

How can I let it keep the entire line?

Sometimes my file contains this:

4165 This package contains 2 1/2" Screws

65 This package contains 12> 1/2" Screws

This package contains 1 screw

  • 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-04T20:41:21+00:00Added an answer on June 4, 2026 at 8:41 pm

    Regrettably, the stream extraction operator >> is not good at the kind of thing you wish it to do. The right way to do what you want is to fetch the whole line by

    std::getline(stringstream, myline);
    

    then to write code to parse the line.

    How to parse the line? Five options come to mind:

    1. Write your own code to do it without relying on special tools.
    2. Use Lex/Flex and Yacc/Bison.
    3. Use Boost Spirit.
    4. Use POSIX <regex.h>.
    5. Use C++11 <regex> or TR1 <tr1/regex>.

    None of these however is entirely trivial. If you want to know, for your application, I’d probably go with choice 1, choice 3 or choice 5. Whatever you choose to do, good luck to you.

    If you don’t know where to start, why don’t you look up std::getline(), presented in <string>, and std::atoi(), presented in <cstdlib>? These should afford you some ideas as to where to go next.

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

Sidebar

Related Questions

I have an instance method that populates a vector of strings. I am trying
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:
I have a vector of strings that i read from the output of a
I have a list that contains 0-3 id numbers like this: [[1]] [1] 2125233
I have a String Vector that contains data like this : 5:34, 5:38, 17:21,
I have a vector of strings which are changing its contents for no apparent
I have some data structures: all_unordered_m is a big vector containing all the strings
I have a vector of strings. Check out my vector, it's awesome : >
I'm trying to export classes from a DLL that contain objects such as std::vectors
I have a large Set<String> that contains many words, say: aaa, cCc, dDD, AAA,

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.