Thread: Accurately explain in detail all the processes are going on, please! What's happening

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    119

    Accurately explain in detail all the processes are going on, please! What's happening

    Code:
    #include <algorithm>
    #include <iostream>
    #include <list>
    #include <string>
    #include <vector>
    
    
    using namespace std;
    
    template<typename T>
    bool do_something(std::vector<T>& vec)
    {
        std::cout << "bool do_something(std::vector<T>& vec)" << std::endl;
        typename vector<T>::iterator iter=vec.begin();
       // vec=++vec;
        std::cout << *iter << std::endl;
        return (vec.begin()!=vec.end());
    }
    
    
    int main()
    {
        list<string> mylist;
        list<string>::iterator loc;
        string son = "Danny";
        loc = std::find(mylist.begin(),mylist.end(),son);
        if (loc == mylist.end())
        {
            cout << "So of course when you make a list, it's empty and searches with find() will fail.\n";
        }
        int S=25; S=S-25;
        for(;S<=10;S++)int F=S;
    
        vector< string >buffer={"Artem","Andryju","Petre"};
        vector< string >::iterator iter = buffer.begin();
        for ( ; iter != buffer.end(); iter++ )
        {
            buffer.push_back( *iter );
            if ( ! do_something( buffer ))
                buffer.pop_back();
        }
    
    
    
    return 0;
    }

    Hello, great to you! I spent forty minutes walking slowly in the debugger, and for a long time thoughtfully carefully examined the debugger.
    I do not exactly understand why it falls. I did not quite expect such effects. Rather, I thought that it would be shown, and then grow and show something like this:
    Artem Andryju Petre then Artem Andryju Petre Artem Andryju Petre and so on.
    But not this, rather incomprehensible, three times writes Artem, only Artem, and after that strangely falls!
    I do not understand .. How exactly does this happen? Why falls?

    Here to you of course I show the code. And yet here I put it right.
    This is a project and it has a compiled file that has a crash.

    http://images.vfl.ru/ii/1490275087/9...f/16570301.bmp

    DropMeFiles – free one-click file sharing service

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    std::vector::push_back - cppreference.com
    If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.
    You're messing around with the content of buffer whilst trying to iterate over it at the same time.

    Oh, and if/when your post is moderated next time, don't post over and over again!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you!!

    Oh, and if / when your post is moderated next time, do not over and over again!

    I am sorry. About 4 seconds I saw the message.
    I did not have time to read. I read English slowly, I did not immediately understand. Please forgive me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Measuring time accurately
    By sigur47 in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2012, 07:33 PM
  2. Can someone explain the following macro in detail?
    By lilzz in forum C Programming
    Replies: 5
    Last Post: 02-23-2011, 01:42 PM
  3. What is happening here please explain
    By jayee_spicyguy in forum C Programming
    Replies: 5
    Last Post: 09-23-2008, 05:27 AM
  4. Explain me what is happening
    By capvirgo in forum C Programming
    Replies: 2
    Last Post: 02-18-2008, 08:26 AM
  5. Rounding Numbers accurately
    By crystaldawn68 in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2001, 02:23 PM

Tags for this Thread