Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Vectors in STL

Reply
Thread Tools

Vectors in STL

 
 
Rookie
Guest
Posts: n/a
 
      10-13-2004
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$


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-13-2004
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
 
Reply With Quote
 
 
 
 
Erik Max Francis
Guest
Posts: n/a
 
      10-13-2004
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.velocityreviews.com/forums/(E-Mail Removed) && 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
 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      10-13-2004
drop the .h

#include <vector>
using std::vector;

int main()
{
vector<int> test;

}

Mike




"Rookie" <(E-Mail Removed)> wrote in message
news:ckk9eg$rhi$(E-Mail Removed)...
> 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$
>
>



 
Reply With Quote
 
Chris Barts
Guest
Posts: n/a
 
      10-14-2004
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/...ngInCPP2e.html

I set followups to comp.lang.c++, since this affects neither Unix nor
Solaris.

 
Reply With Quote
 
=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=
Guest
Posts: n/a
 
      10-14-2004
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.
 
Reply With Quote
 
James Antill
Guest
Posts: n/a
 
      10-14-2004
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 -- (E-Mail Removed)
Need an efficient and powerful string library for C?
http://www.and.org/vstr/

 
Reply With Quote
 
Paul Floyd
Guest
Posts: n/a
 
      10-14-2004
On Wed, 13 Oct 2004 15:15:25 -0700, Rookie <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
Need help with stl vectors (?) Tom C++ 1 12-14-2003 05:05 PM
C++ STL valarrays vs. vectors Michael Aramini C++ 10 11-03-2003 11:15 AM
vectors stl with pointers berthelot samuel C++ 3 07-30-2003 12:01 PM



Advertisments