Vectors in STL

Discussion in 'C++' started by Rookie, Oct 13, 2004.

  1. Rookie

    Rookie Guest

    Hi,

    While compiling the following code I get a bundle of warnings. Can anyone
    tell me why? Should I be using some option while compiling (right now I just
    have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    If so which is the right header? Hope to hear from someone. Thanks!

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <vector.h>

    int main(int argc,char* argv[])
    {
    vector<int> test;

    printf("test.size()=%d\n",test.size());
    }


    Warnings:
    bash-2.05b$ g++ -o test.o test.cpp
    In file included from
    /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/vector.h:59,
    from test.cpp:4:
    /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/backward_warning.h:32:2:
    warning: #warning This file includes at least one deprecated or antiquated
    header. Please consider using one of the 32 headers found in section
    17.4.1.2 of the C++ standard. Examples include substituting the <X> header
    for the <X.h> header for C++ includes, or <sstream> instead of the
    deprecated header <strstream.h>. To disable this warning
    use -Wno-deprecated.
    bash-2.05b$
     
    Rookie, Oct 13, 2004
    #1
    1. Advertising

  2. Rookie wrote:
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    > If so which is the right header? Hope to hear from someone. Thanks!
    >
    > Code:
    > #include <stdio.h>
    > #include <string.h>
    > #include <stdlib.h>
    > #include <vector.h>


    There is no standard header <vector.h>. You should use <vector>.

    >
    > int main(int argc,char* argv[])
    > {
    > vector<int> test;


    Change this to

    std::vector<int> test;

    as soon as you switch to including <vector>

    >
    > printf("test.size()=%d\n",test.size());
    > }
    > [...]


    Victor
     
    Victor Bazarov, Oct 13, 2004
    #2
    1. Advertising

  3. Rookie wrote:

    > While compiling the following code I get a bundle of warnings. Can
    > anyone
    > tell me why? Should I be using some option while compiling (right now
    > I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong
    > header?
    > If so which is the right header? Hope to hear from someone. Thanks!
    >
    > Code:
    > #include <stdio.h>
    > #include <string.h>
    > #include <stdlib.h>
    > #include <vector.h>


    These includes are now

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <vector>

    > warning: #warning This file includes at least one deprecated or
    > antiquated
    > header. Please consider using one of the 32 headers found in section
    > 17.4.1.2 of the C++ standard. Examples include substituting the <X>
    > header
    > for the <X.h> header for C++ includes, or <sstream> instead of the
    > deprecated header <strstream.h>. To disable this warning
    > use -Wno-deprecated.


    .... just as the warning indicates.

    --
    __ Erik Max Francis && && http://www.alcyone.com/max/
    / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
    \__/ Can I be your friend / 'Till the end
    -- India Arie
     
    Erik Max Francis, Oct 13, 2004
    #3
  4. Rookie

    Michael Guest

    drop the .h

    #include <vector>
    using std::vector;

    int main()
    {
    vector<int> test;

    }

    Mike




    "Rookie" <> wrote in message
    news:ckk9eg$rhi$...
    > Hi,
    >
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I

    just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong

    header?
    > If so which is the right header? Hope to hear from someone. Thanks!
    >
    > Code:
    > #include <stdio.h>
    > #include <string.h>
    > #include <stdlib.h>
    > #include <vector.h>
    >
    > int main(int argc,char* argv[])
    > {
    > vector<int> test;
    >
    > printf("test.size()=%d\n",test.size());
    > }
    >
    >
    > Warnings:
    > bash-2.05b$ g++ -o test.o test.cpp
    > In file included from
    > /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/vector.h:59,
    > from test.cpp:4:
    > /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/backward_warning.h:32:2:
    > warning: #warning This file includes at least one deprecated or antiquated
    > header. Please consider using one of the 32 headers found in section
    > 17.4.1.2 of the C++ standard. Examples include substituting the <X> header
    > for the <X.h> header for C++ includes, or <sstream> instead of the
    > deprecated header <strstream.h>. To disable this warning
    > use -Wno-deprecated.
    > bash-2.05b$
    >
    >
     
    Michael, Oct 14, 2004
    #4
  5. Rookie

    Chris Barts Guest

    On Wed, 13 Oct 2004 15:15:25 -0700, Rookie wrote:

    > Hi,
    >
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    > If so which is the right header? Hope to hear from someone. Thanks!


    What everyone else said, and it looks like you might need a good, recent
    book on the language. Bruce Eckel has a book on beginners' C++ free to
    download here: http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

    I set followups to comp.lang.c++, since this affects neither Unix nor
    Solaris.
     
    Chris Barts, Oct 14, 2004
    #5
  6. Rookie wrote:
    > Hi,
    >
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    > If so which is the right header? Hope to hear from someone. Thanks!
    >
    > Code:
    > #include <stdio.h>
    > #include <string.h>
    > #include <stdlib.h>
    > #include <vector.h>
    >
    > int main(int argc,char* argv[])
    > {
    > vector<int> test;
    >
    > printf("test.size()=%d\n",test.size());
    > }
    >
    >
    > Warnings:
    > bash-2.05b$ g++ -o test.o test.cpp
    > In file included from
    > /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/vector.h:59,
    > from test.cpp:4:
    > /usr/usc/gnu/gcc/3.3.2/include/c++/3.3.2/backward/backward_warning.h:32:2:
    > warning: #warning This file includes at least one deprecated or antiquated
    > header. Please consider using one of the 32 headers found in section
    > 17.4.1.2 of the C++ standard. Examples include substituting the <X> header
    > for the <X.h> header for C++ includes, or <sstream> instead of the
    > deprecated header <strstream.h>. To disable this warning
    > use -Wno-deprecated.
    > bash-2.05b$

    This warning is actually rather good. It tells you exactly what is your
    problem, how to "fix" it, and even a refrence to the relevant standard
    paragraph.
     
    =?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=, Oct 14, 2004
    #6
  7. Rookie

    James Antill Guest

    On Wed, 13 Oct 2004 15:15:25 -0700, Rookie wrote:

    > Hi,
    >
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    > If so which is the right header? Hope to hear from someone. Thanks!
    >
    > Code:
    > #include <stdio.h>
    > #include <string.h>
    > #include <stdlib.h>
    > #include <vector.h>
    >
    > int main(int argc,char* argv[])
    > {
    > vector<int> test;
    >
    > printf("test.size()=%d\n",test.size());
    > }


    Apart from the other problems, the printf above should be...

    printf("test.size()=%zu\n", test.size());

    ....and you might even need a cast, if std::vector<int>::size_type can be
    anything else.

    --
    James Antill --
    Need an efficient and powerful string library for C?
    http://www.and.org/vstr/
     
    James Antill, Oct 14, 2004
    #7
  8. Rookie

    Paul Floyd Guest

    On Wed, 13 Oct 2004 15:15:25 -0700, Rookie <> wrote:
    > While compiling the following code I get a bundle of warnings. Can anyone
    > tell me why? Should I be using some option while compiling (right now I just
    > have g++ -o test.o test.cpp)? Or is it because I am using the wrong header?
    > If so which is the right header? Hope to hear from someone. Thanks!


    I think that there are two fundamental problems
    a) you can't read
    b) you are bothering thousands of people with your reading inability.

    Paul
    --
    Paul Floyd http://paulf.free.fr (for what it's worth)
    Surgery: ennobled Gerald.
     
    Paul Floyd, Oct 14, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. berthelot samuel

    vectors stl with pointers

    berthelot samuel, Jul 30, 2003, in forum: C++
    Replies:
    3
    Views:
    471
    John Harrison
    Jul 30, 2003
  2. Michael Aramini

    C++ STL valarrays vs. vectors

    Michael Aramini, Sep 2, 2003, in forum: C++
    Replies:
    10
    Views:
    13,149
    vrambati
    Nov 3, 2003
  3. Tom
    Replies:
    1
    Views:
    347
    Moonlit
    Dec 14, 2003
  4. Replies:
    3
    Views:
    702
    Shadowman
    Mar 26, 2008
  5. Guest
    Replies:
    0
    Views:
    447
    Guest
    Sep 14, 2005
Loading...

Share This Page