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

  • Home
  • SEARCH
  • 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 6154831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:19:39+00:00 2026-05-23T20:19:39+00:00

I have a comma separated integers and I want to store them in std::vector<int>

  • 0

I have a comma separated integers and I want to store them in std::vector<int>. Currently I am manually doing it. Is there any built-in function which did the above functionality?

Edit:

I was in hurry and forget to put full details
Actually i have string (to be exact Unicode string) containing CSvs e.g. “1,2,3,4,5”
Now i want to store them in std::vector<int> so in above case my vector would have five elements pushed into it. Currently i am doing this by manual but its slow as well as there is lot of mess with that 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-05-23T20:19:40+00:00Added an answer on May 23, 2026 at 8:19 pm

    You can do this using purely in STL for simplicity (easy to reading, no complex libs needed), which will be fast for coding, but not the fastest in terms of execution speed (though you can probably tweak it a little, like pre-reserving space in the vector:

    std::vector<int> GetValues(std::wstring s, wchar_t delim)
    {
        std::vector<int> v;
        std::wstring i;
        std::wstringstream ss(s);
        while(std::getline(ss,i,delim))
        {
            std::wstringstream c(i);
            int x;
            c >> x;
            v.push_back(x);
        }
    
        return v;
    }
    

    (no forwarding(&&) or atoi to keep the code portable).

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

Sidebar

Related Questions

I have a list of input words separated by comma. I want to sort
I have a comma separated value table that I want to read in Python.
I have a comma-separated string that I want to convert into an array, so
If I have a std::string containing a comma-separated list of numbers, what's the simplest
I have a comma separated CSV file looks like: customer1,customer2,,customer4, ,customer2,,customer4, custome1,,customer3,, I want
I have implemented a function TraverseStringClockwise which takes a comma separated string of integers,
I have a comma separated list of strings like the one below. a,b ,c
If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d
I have a bunch of pretty large CSV (comma separated values) files and I
I have a DB table that contains a comma separated list of ID's (ints)

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.