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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:24:15+00:00 2026-06-12T06:24:15+00:00

this is what im doing, im getting some info from a .txt file those

  • 0

this is what im doing, im getting some info from a .txt file those are numbers of course when im getting them i get them as strings in a list of strings…(i know it could be chars but in this example is strings) so when im inserting them on another list it should be something like this

list<int> l;

//i is the iterator for the 1st list that already has all the strings
l.push_back(atoi(*i.c_str()));

i cant use c_str() because i is trying to access the elements of the list is there anyway i can do this?

basically what im trying to do is just getting my strings from one list and change them to integers while keeping the list format

any help would be really appreciated thank you

  • 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-12T06:24:16+00:00Added an answer on June 12, 2026 at 6:24 am

    You need (*i).c_str() or i->c_str().

    You probably want to do the job as a whole a bit differently, specifically in a way that doesn’t require you to deal directly with iterators at all. For example, let’s assume what you have is:

    list<string> strings;
    list<int> ints;
    

    Then I’d almost certainly do the job with std::transform, probably something like this:

    std::transform(strings.begin(), strings.end(), std::back_inserter(ints),
        [](std::string const &in) { return atoi(in.c_str()); });
    

    or:

    transform(begin(strings), end(strings), std::back_inserter(ints),
              [](string const &in) { return stoi(in); });
    

    In case you’re not familiar with it, that last line is a lambda (new with C++11). Assuming you’re using a fairly new compiler (e.g., gcc 4.7.x or newer, VC++ 2010 or newer) it shouldn’t be a problem.

    I’d also seriously consider using std::vector instead of std::list. I’ve virtually never found std::list to be a particularly good choice. Even situations that should theoretically favor a linked list usually don’t, at least in my experience.

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

Sidebar

Related Questions

Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
Linux GCC 4.4.2 I am doing some socket programming. However, I keep getting this
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
I'm having issues in getting Core Data info from 3 linked entities. Some of
I need a little help getting this script doing what I want it to.
I am getting the index of a row by doing this: row.parent().children(tr).index(row) Is there
I Believe I'm doing this correctly but it is not getting the stored cookie
I'm doing a Firefox addon but I'm currently getting this error in the Error
I am doing very simple int division and I am getting odd results. This
I am doing a minesweeper program for school, but i keep getting this error

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.