Vectors in STL

R

Rookie

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$
 
V

Victor Bazarov

Rookie said:
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 said:
int main(int argc,char* argv[])
{
vector<int> test;

Change this to

std::vector<int> test;

as soon as you switch to including said:
printf("test.size()=%d\n",test.size());
}
[...]

Victor
 
E

Erik Max Francis

Rookie said:
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 said:
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.
 
M

Michael

drop the .h

#include <vector>
using std::vector;

int main()
{
vector<int> test;

}

Mike
 
C

Chris Barts

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.
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Rookie said:
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.
 
J

James Antill

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.
 
P

Paul Floyd

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top