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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:04:36+00:00 2026-06-05T23:04:36+00:00

[SOLVED] See my answer below. I am trying to use stringstream (named ss) to

  • 0

[SOLVED] See my answer below.

I am trying to use stringstream (named ss) to convert some strings to ints and some to double and such, but the values are all coming out wrong. I have a vector of strings named vec, initialized like this:
[0] = ID # in hex
[1] = phone number
[2] = last name
[3] = first name
[4] = sales number
[5] = percent of sales
Now I go through the vector and put the values into int, string, or double:

std::string lname, fname, pnum;
int ID;
double sales, percent;

if(vec.size()!=6) {
    //throw exception
}
else {
    ss<<std::hex<<vec[0];
    ss>>ID;

    pnum = vec[1];
    lname = vec[2];
    fname = vec[3];

    ss<<vec[4];
    ss>>sales;

    ss<<vec[5];
    ss>>percent;
}

but the output looks like this for every customer. What are my ints always 1 and my doubles always this weird number?

Customer made: Langler Tyson 1 7667230284 2.12303e-314 2.12201e-314

  • 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-05T23:04:38+00:00Added an answer on June 5, 2026 at 11:04 pm

    You will need to introduce a separator between the numbers to be ablew to extract them out:

    ss << vec[0] << " ";
    ss >> ID;
    ss << vec[4] << " ";
    ss >> sales;
    ss << vec[5] << " ";
    ss >> percent;
    

    Besides this, you need to revert back to the original decimal format after extracting the ID:

    ss << hex;
    ss << vec[0] << " ";
    ss >> ID;
    ss << dec;
    

    Also, because you use the same ss stream to extract the vector elements, the state of the stream is in error after the last vector element is extracted. You need to clear the error state before further insertion/extraction. Using a new stream will solve the problem as well:

    ss = stringstream();
    ss << hex;
    ss << vec[0] << " ";
    ss >> ID;
    ss << dec;
    ss << vec[4] << " ";
    ss >> sales;
    ss << vec[5] << " ";
    ss >> percent;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Problem solved now, see answers below) Hello, in my app I am trying to
[EDIT: Problem solved. Please see my answer below.] In my app I call the
SOLVED See my answer below. Question left unchanged for anyone else who has trouble
SOLVED! See my self-answer below. I'm building two Metro-style apps using Javascript and HTML,
[SOLVED (see answer below)] I am using SpreadsheetWorker API to make working with Open
UPDATE: SOLVED!!! Please see the answer I added below Does anyone know if there
Problem solved: Thanks guys, see my answer below. I have a website running in
Edit: I have solved this by myself. See my answer below I have set
Update: Solved, with code I got it working, see my answer below for the
Solved: see answer below I am sub-classing Dialog to create a dialog with a

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.