Thread: What is a slist, standard and non-standard library, connectivity and use.

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

    What is a slist, standard and non-standard library, connectivity and use.

    What are libraries for custom slist?

    Using stlport?

    Why in the source code in a way inverted slash and what to do?

    Will show the correct useful include, compile the show, please!


    Code:
    #include<vector>
    #include<iostream>
    #include <string>
    #include <list>
    #include <deque>
    #include <map>
    #include <set>
    //#include <boost\container\slist.hpp>
    #include <stlport\slist>
    
    int main()
    {
    std::string son( "Danny" );
    std::list<std::string>::iterator iter;
    iter = find( slist.begin(), slist.end(), son );
    slist.insert( iter, spouse );
    
    for ( iter = slist. begin();
       iter != slist.end(); ++iter )
       do_something_with_element( *iter );
    
    return 0;
    }

    I just downloaded it and have a path to the compiler.
    If you will be good enough.
    Source code STLport gave way to the back of the line.
    And many, and perhaps in many ways.
    What to do?

    Code:
    #include <STL / _prolog.h>

    Here e.g.
    Code:
    Here my record compiler accepts.
     #include <STLPort \ slist>
    
    #include <Stl / _prolog.h>
    And I do not understand. And as he wrote STLport.
    E: \ STLport-5.2.1 \ STLPort \ slist | 20 | fatal error: stl / _prolog.h: No such file or directory |

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    #include <stlport\slist>
    It is normal for includes to use forward slashes "/"; It is NOT normal for them to contain back slashes "\".

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you. So what to do?




    In the book C ++ Primer many slist used. I do not understand how to use these examples, I have not obtained. I want to be thoroughly used slist and custom data types.
    Last edited by Dmy; 03-15-2017 at 10:26 AM.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Normally, a slash is an indication of a directory. So #include<stlport/slist.hpp> would mean that your compiler knows where to find a folder called "stlport" and inside of such folder is slist.hpp.

    If you need help getting the above part to work, then we need to know what IDE you are using to write code.

    STLport is a portable, third-party implementation (as in not you or your compiler) of the Standard Template Library, which comes with extra features. It is meant to be an alternative to a native compiler version. That is pretty much all you need to know if you're starting out in C++.

    I notice that you have other list libraries in your posts, like boost and your compiler's native list type. You do have to know which library you want to use. I personally haven't read C++ Primer, but from what you say about it, it sounds like you need to use the STLport or the boost version, but not both, in order to learn the most from the book. Slist is not a standard type, but it is an implementation of a very common data structure: a singly-linked list; a class with a pointer to the next object.

    This is the documentation page for the STLport version of slist: slist<T, Alloc>
    Index for STLport in general: Standard Template Library Programmer's Guide

    What to do now? Well, read your book and practice. Other than telling you what it is, there isn't much to say.
    Last edited by whiteflags; 03-15-2017 at 12:21 PM.

  5. #5
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you for the detailed answer!

    I use IDE code :: blocks.
    I do not know what #include is needed.
    The truth is that the code does not compile.
    Indeed, that's what I want, to compile an example.
    And I'm happy to download and I'll learn how to use different libraries.
    Last edited by Dmy; 03-15-2017 at 01:40 PM.

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    It should be noted that C++11 STL has forward_list, which is a singly-linked list. Presumably your book is pre-C++11.

  7. #7
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Code:
     "                                 c + + Primer - Basic Language (9)
    
                                                                           1.istream_iterator  
       The head of the container insert elements:  
       slist.insert (slist.begin (), value);  
       Insert elements in the container before the specified element:  
       string son ("Danny");  
       list <string> :: iterator iter;  
      
       iter = find (slist.begin (), slist.end (), son);  
       slist.insert (iter, spouse);  
       / * Find () returns end () iterator Find the position of the  element in the container, or return the container to show that this  query failed.   * /  
       / * Insert () the first parameter is a position (point to a  position in the container iterator), the second parameter is the value  to be inserted, this value is inserted into the front of the location  pointed to by the iterator.   * /  
      
       The second form of the insert ():  
       vector <string> svec;  
       / / ...  
      
       String Anna ("Anna");  
       svec.insert (svec.begin (), 10, anna); / * insert at the head of the svec 10 Anna * /  
      
       insert () The third form:  
       string sarray [4] = {"quasi", "simba", "frollo", "scar"};  
       svec.insert (svec.begin () sarray, sarray +4) ;/ * a pair  iterator or a pointer to indicate that the sequence to be inserted into  the container * /  
       3 delete the elements erase () operation:  
       To delete an element:  
       slist.erase (ITER) ;/ * delete iter within the meaning of the element * /  
      
       To delete multiple elements marked by a pair of iterator:  
       slist.erase (begin_iter, end_iter); / * the elements between delete begin_iter and end_iter * /
                                 
    "

  8. #8
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you! I'll go to dinner.

  9. #9
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you!! Very interesting about forward_list. But the author does not seem to mention it.

    No, the issue is not settled.
    Last edited by Dmy; 03-15-2017 at 05:28 PM.

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Dmy View Post
    Thank you for the detailed answer!

    I use IDE code :: blocks.
    I do not know what #include is needed.
    The truth is that the code does not compile.
    Indeed, that's what I want, to compile an example.
    And I'm happy to download and I'll learn how to use different libraries.
    OK, well, it's worth mentioning that the specific page you posted is not trying to use STLport's slist; it is merely the name of the object.

    Code:
       list <string> :: iterator iter;  
      
       iter = find (slist.begin (), slist.end (), son);  
       slist.insert (iter, spouse);
    Unfortunately, the author has neglected to declare slist in the quoted portion, but we can presume from the type of the iterator and how that iterator is used that slist is defined as a list<string> type variable.

    Additionally, objects use the dot operator to call their member functions.
    Code:
    slist.insert (iter, spouse);
    The stuff on the left side of the dot must be an object name, meaning that you are calling insert on something called slist.

    Frankly, I did what you wouldn't do, and read the README and INSTALL files included with the STLport download. In order to install the library properly, you have to configure it with a specific compiler, and Microsoft compilers are the easiest to configure due to presets. Since you are using codeblocks, 1) you are using a port for windows of GCC and 2) GCC on windows happens to work horribly with STLport. It may be easier for you to learn with your compiler's version of the STL. Meaning:

    use #include <list> instead of #include <stlport/list>
    in fact don't include anything starting with stlport/

    From there you can just read your book and practice. Since I'm so nice, I'll provide something to play with that should look a lot like your book.
    Code:
    #include <algorithm>
    #include <iostream>
    #include <list>
    #include <string>
    #include <vector>
    
    
    using namespace std;
    
    
    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";
        }
    
    
        cout << "Let's add " << son << " to the list and repeat the search!\n";
        mylist.push_back(son);
        loc = find(mylist.begin(),mylist.end(),son);
        if (loc != mylist.end())
        {
            cout << "Found it! " << *loc << "\n";
        }
    
    
        string spouse = "Bob";
        mylist.insert(loc,spouse);
    
    
        for (list<string>::iterator it = mylist.begin();
            it != mylist.end();
            ++it)
            {
                cout << *it << "->";
            }
        std::cout << "\n";
    
    
        cout << "Inserting more stuff...\n";
        vector<string> svec(4);
        svec[0] = "quasi";
        svec[1] = "simba";
        svec[2] = "frolo";
        svec[3] = "scar";
        mylist.insert(mylist.begin(),svec.begin(),svec.end());
        svec.clear();
    
    
        string el = "simba";
        cout << "Let's erase the " << el << " element using what we\'ve learned.\n";
        loc = find(mylist.begin(),mylist.end(),el);
        mylist.erase(loc);
    
    
        for (list<string>::iterator it = mylist.begin();
            it != mylist.end();
            ++it)
            {
                cout << *it << "->";
            }
        cout << "\n";
    }
    Last edited by whiteflags; 03-15-2017 at 07:18 PM.

  11. #11
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    A huge thank you! Thank you very much! Very good code, I'm very pleasant!
    Last edited by Dmy; 03-19-2017 at 03:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI with Standard Library
    By Sly in forum C Programming
    Replies: 2
    Last Post: 03-13-2009, 05:06 PM
  2. The standard C Library API
    By boyfarrell in forum C Programming
    Replies: 4
    Last Post: 10-11-2008, 02:05 PM
  3. Standard C++ library
    By nevermind in forum C++ Programming
    Replies: 4
    Last Post: 11-22-2002, 04:27 PM
  4. C Standard Library
    By JoshG in forum C Programming
    Replies: 2
    Last Post: 07-17-2002, 09:09 AM
  5. C standard library
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 12:08 PM

Tags for this Thread