Results 1 to 7 of 7

Thread: STL libraries

  1. #1
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default STL libraries

    Good morning to everyone.... I use LINUX-FEDORA
    In Qt CREATOR.....
    I want to compile a console application in C++.
    I need to use STL library ....

    I write:

    #include <vector>
    /*
    I even used and this
    #include <QVector>
    */
    ........
    int main()
    {
    vector<int> v;
    /*
    I even used and this
    std::vector<int> v;
    */
    ........
    vector<int>::iterator it = v.begin();
    ........
    }

    The compiler sais:
    'iteraror' is not a member of 'std::vector<int>'
    expected ';' before 'it'
    'it' was not declared in this scope

    The same things, with g++ (in LINUX), devcpp (in WINDOWS)
    Where is the STL library in Qt CREATOR ??
    Maybe I must install in LINUX, the STL from somewhere ??
    Thanks in advance ...!!!!

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: STL libraries

    You haven't posted your whole code. For example, it appears that the compiler accepts the declaration "vector<int> v;", therefore you must have put a "using" directive somewhere. Is that right?

    It seems that the error is unrelated to Qt. Can you confirm that you can reproduce it on a minimal program without involving Qt (be it libraries or tools, such as QtCreator) at all?

  3. #3
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: STL libraries

    My friend I discovered something
    In this code IT WORKS !!!

    // -------------------------------------------
    #include <iostream>
    #include <vector>

    using namespace std;

    int main()
    {
    cout << endl;

    vector<int> v1;
    for(int i=1; i<10; i+=2)
    {
    v1.push_back(i);
    }

    for(int i=1; i<8; i+=2)
    {
    cout << v1[i] << endl;
    }

    cout << endl;
    return 0;
    }
    // -------------------------------------------

    But the problem appears only if I use iterators .....
    I googled and I found that if I use typedef, the problems stops ....
    Look these ....

    // -------------------------------------------
    #include <iostream>
    #include <vector>
    //LOOK THIS ....
    typedef std::vector<int>::iterator IT;

    using namespace std;

    int main()
    {
    cout << endl;

    vector<int> v1;
    for(int i=1; i<10; i+=2)
    {
    v1.push_back(i);
    }

    std::vector<int> v2(v1);

    std::vector<int> v3;

    for(int i=1; i<20; i+=2)
    {
    v3.push_back(3*i);
    }

    IT iter = v1.begin();

    while(iter != v1.end())
    {
    cout << *iter;
    iter++;
    }

    iter = v2.begin();

    while(iter != v2.end())
    {
    cout << *iter;
    iter++;
    }

    IT it1 = v3.begin();
    IT it2 = v3.end();

    vector<int> v4(it1+5, it2-2);

    iter = v4.begin();

    while(iter != v4.end())
    {
    cout << *iter;
    iter++;
    }


    cout << endl;
    return 0;
    }

    // -------------------------------------------

    Very strange because
    1. It needs "std::" allthough I wrote:
    using namespace std;
    2. all books I've read say that we use
    vector<int>::iterator iter = v1.begin();
    without typedef
    3.Sorry but I am Greek and I did a lot of mistakes while writing ....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: STL libraries

    How is that all related to Qt?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: STL libraries

    My friend I don't think it is related with qt...
    It's about C++. I would be grateful to you if you can help me....
    Thank you a lot for replying to me. I own to you ....
    Why the iterators in <vector>, cannot recognized .....
    Thanks in advance.... A C++ lover !!!!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: STL libraries

    Apparently the syntax of your program is not correct.

    This builds just fine for me:
    Qt Code:
    1. #include <vector>
    2.  
    3. int main() {
    4. std::vector<int>::iterator iter;
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 

    So does this:

    Qt Code:
    1. #include <vector>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6. vector<int>::iterator iter;
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    $ g++ --version
    g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: STL libraries

    My friend thank you very much for your help...
    I will note these you just wrote to me.... Thanks for everything !!

Similar Threads

  1. Replies: 4
    Last Post: 5th November 2011, 01:38
  2. Qt Libraries
    By uxbod in forum Newbie
    Replies: 0
    Last Post: 12th November 2010, 11:58
  3. Using .so libraries under Mac
    By maverick_pol in forum Qt Programming
    Replies: 6
    Last Post: 6th January 2008, 22:41
  4. Qt Libraries
    By Seth in forum Newbie
    Replies: 1
    Last Post: 17th April 2007, 04:53
  5. Qt 3.3 libraries
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2006, 17:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.