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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:31:44+00:00 2026-06-18T19:31:44+00:00

This function below simply takes a string that is being filled with 64 bits

  • 0

This function below simply takes a string that is being filled with 64 bits integer, and each value is separated by a delimiter character, which will be put into the vector.

vector<unsigned long long int> getAllNumbersInString(string line, char delim){
    vector<unsigned long long int> v;

    string word;
    stringstream stream(line);
    unsigned long long int num;

    while(getline(stream, word, delim))
        num = atol(word.c_str());
        v.push_back(num);
    }

    return v;
}

This function works fine when, for instance, we have ‘,’ as delimiter, however, the delimiter will fail if the data in the string variable “line” is like this:

     432   12332    2234   12399   

While it seems the data uses white space as a delimiter, with the code above, the whole code will fail logically. For instance, the white space between white space is undefined and atol will return 0, and putting these zeros into the vector.

In order to better guard against these anomolies, what are the measures I should put into this code?

  • 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-18T19:31:46+00:00Added an answer on June 18, 2026 at 7:31 pm

    Is there some reason you can’t/won’t just use something like this?:

    while (stream >> num)
       v.push_back(num);
    

    or just:

    vector<unsigned long long int> getAllNumbersInString(string line) { 
        istringstream stream(line);  
        typedef unsigned long long int T;
    
        vector<T> v((istream_iterator<T>(stream)), istream_iterator<T>());
        return v;
    }
    

    If you have to deal with delimiters other than whitespace, you can create a ctype facet to specify what else should be treated as delimiters.

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

Sidebar

Related Questions

How is this possible that the str_replace() function below returns biWeekly and not Every
somebody mentioned that the function (in this case a method) below is no good
In the code below: DbModels.prototype.updateById = function(_collection, id, field, value, callback) { this.getCollection(_collection, function(error,
I wrote a function which takes in a string and simply encodes the string
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
If I run the function below before defining it, I will get this error...
In the js code specified below - var tclass = function(){ this.func2=function(){console.log('func2')}; this.b={ func1:
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I'm using this script below for loading a hidden div, inside another: $(document).ready(function(){ $(function()
So I wrote the code below: jQuery('#contentWrapper').delegate(.addButton, click, function(){ addRow(jQuery(this)); }); function addRow(thisButton){ var

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.