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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:45+00:00 2026-05-25T14:23:45+00:00

list<string> mylist; mylist.push_back(random stuff); list<string>::iterator it; it=mylist.begin(); string mystr; //and this doesn’t work: mystr=*it;

  • 0
list<string> mylist;
mylist.push_back("random stuff");
list<string>::iterator it;
it=mylist.begin();
string mystr;
//and this doesn't work:
mystr=*it;

Let’s say I have a list<string> mylist and it has 3 items. Since I can’t work on the characters of each element I must copy what item I want to a simple string or a char buffer. But I can’t find a way at all, I’ve tried with pointers to arrays as well.
So is there a way to copy those items out of the list ?

Edit:
Yeah sorry , revisited my code , the project that is , and found the error to be somewere else, i was copying from listmylist to a string mystr, with the help of an iterator, and i was using a for loop that had the condition to stop when it encountered the character ‘\0’ put when i was copying it, it didn’t copy the ‘\0’ in my string so in the end i had to put it manually so the function would not work outside the string
Good code:

    string temp;
    list<string>::iterator it;
    it=mylist.begin();//let's say myslist has "random stuff"
    temp=*it;//this does not copy the '\0'
    temp+='\0';//so i add it myself 
    for(int n(0);temp[n]!='\0';n++)//now the for loop stops properly
        cout<<temp[n];
  • 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-25T14:23:45+00:00Added an answer on May 25, 2026 at 2:23 pm

    The code works great and outputs the correct result. Also, you can work with characters of each element like this:

    for (list<string>::iterator iter = mylist.begin(); iter != mylist.end(); ++iter)
    {
        char c = (*iter)[0];  //this is the first character.
    }
    

    You can cycle through the string with an iterator too even, strings have them as well 🙂 Though strings support random-access-iterators, so you can just access them as arrays like a c-string as I showed in the for loop.

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

Sidebar

Related Questions

considering this example: public static void main(final String[] args) { final List<String> myList =
using namespace std; class myList { public: mylist():_internalList(),_lastPostition(0) { } typedef list<string>::iterator Itr; bool
I am using this code: //I store the website urls in mylist list<string> mylist=new
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2
I've created and populated a generic list of strings like this: Dim MyList As
class Program { static void Main(string[] args) { List<A> myList = new List<A> {new
I got a list, programmed like this: public class MyList<T> . Is there any
I'm having a List of String like List<string> MyList = new List<string> { A-B,
I'm having a list of string List<String> MyList=new List<String>{ A,B , C,D,E , F,G

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.