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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:48:51+00:00 2026-06-02T07:48:51+00:00

I have the following function to read in a stream of text and chop

  • 0

I have the following function to read in a stream of text and chop it up into a vector of a given type:

template<class Type>
void parse_string(std::vector<Type> &type_vector, char *string) 
{
    std::stringstream stream(string);
    while (stream.good()) 
    {
        Type t;
        stream >> t;
        type_vector.push_back(t);
    }
}

The char *string parameter is a chunk of text representing either floating point numbers or strings each separated with either ' ' or '\n'.

Now my issue is that when given a std::vector<float> type_vector, the parse_string function will separate by both the ' ' or '\n' delimiters. For example for:

0.01 0.02 0.03 0.04
0.05 0.06 0.07 0.08

it will read '0.04' and '0.05' as separate tokens. This is what I want!

However if given a std::vector<std::string> type_vector, the parse_string will only separate by ' '. Therefore if my text is as follows:

root_joint left_hip left_knee left_ankle
left_foot right_hip right_knee right_ankle

it will read ‘left_ankleleft_foot’ as a single token. It doesn’t seem to take into account that there is a '\n' between 'left_ankle' and 'left_foot'.

What is causing this?

EDIT:

The exact char* arguments as seen in the debugger are as follows:

0.01 0.02 0.03 0.040.05 0.06 0.07 0.08

root_joint left_hip left_knee left_ankleleft_foot right_hip right_knee right_ankle

So it seems to completely ignore the ‘\n’ from the file…

EDIT2:

Okay I figured out what I was doing wrong. As many of you pointed out, it had nothing to do with stringstream.

My parser required a std::vector copy of the file. In the process of reading the file into a string and converting it into the vector, I used the getLine(std::ifstream, std::string) function, which as you can guess, strips the ‘\n’ newline character.

  • 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-02T07:48:52+00:00Added an answer on June 2, 2026 at 7:48 am

    You are reading the string incorrectly, so that \n is discarded. \n should lead to a split.

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

Sidebar

Related Questions

I have the following template function used to dump data of any standard type
I have following function in one Activity public void AppExit() { Editor edit =
I have the following function set up to sequentially fade in divs (with class
I have written the following C# function: static string ReadLineCRLF(System.IO.Stream Stream, ref byte[] sharedBuffer,
In my MVC application in Controller i have following function to add and focus
have the following function on my collection : getFiltered: function (status, city) { return
I have the following function to remove a DOM element div, $('#emDiv').on(click, ':button[data-emp-del=true]', function
I have the following function //simple function with parameters and variable function thirdfunction(a,b,c,d){ console.log(the
I have the following function: func fitrange(a, x, b int) int { if a
I have the following function in a PHP script, which returns and API call:

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.