Doubt regarding C++ using STL ( VERYYY URGENT!!!! PLEASE HELP )

E

edu.mvk

i want to write a simple prog like below using vectors...

#include<vector>
using namespace std
int main()
{
vector<int> v;
int i,num;
for(i=0;i<10;i++)
{
num = i;
cout << num << " ";
// v.push_back( num );
}
int i=10;
cout << i;
}

But after compiling this code using "gcc" i am getting the following
errors....
****************************************************************************************
vectr_ptr.cpp:4: syntax error before `int'
vectr_ptr.cpp:15: syntax error before `<<' token

/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp&) [with _Tp = size_t]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:793: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__a' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: (Each undeclared
identifier is
reported only once for each function it appears in.)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__b' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 =
const
signed char*]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:805: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last2' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first2' undeclared
(first
use this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last1' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first1' undeclared
(first
use this function)

********************************************************************************************

i am getting the above errors only when i include this stmt in the code
:

" using namespace std "

if i remove the statement from the code, i'm getting the following
errors....
*****************************************************************************************
vectr_ptr.cpp: In function `int main()':
vectr_ptr.cpp:6: `vector' undeclared (first use this function)
vectr_ptr.cpp:6: (Each undeclared identifier is reported only once for
each
function it appears in.)
vectr_ptr.cpp:6: syntax error before `>' token
vectr_ptr.cpp:11: `cout' undeclared (first use this function)
vectr_ptr.cpp:14: redeclaration of `int i'
vectr_ptr.cpp:7: `int i' previously declared here
vectr_ptr.cpp:14: declaration of `int i'
vectr_ptr.cpp:7: conflicts with previous declaration `int i'
*******************************************************************************************

can anybody please help me in compiling this code successfully and
explain me why am i getting these errors

Thanks...
 
O

onkar

use ; after using namespace..
use #include<iostream>



edu.mvk said:
i want to write a simple prog like below using vectors...

#include<vector>
using namespace std
int main()
{
vector<int> v;
int i,num;
for(i=0;i<10;i++)
{
num = i;
cout << num << " ";
// v.push_back( num );
}
int i=10;
cout << i;
}

But after compiling this code using "gcc" i am getting the following
errors....
****************************************************************************************
vectr_ptr.cpp:4: syntax error before `int'
vectr_ptr.cpp:15: syntax error before `<<' token

/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp&) [with _Tp = size_t]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:793: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__a' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: (Each undeclared
identifier is
reported only once for each function it appears in.)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__b' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 =
const
signed char*]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:805: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last2' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first2' undeclared
(first
use this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last1' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first1' undeclared
(first
use this function)

********************************************************************************************

i am getting the above errors only when i include this stmt in the code
:

" using namespace std "

if i remove the statement from the code, i'm getting the following
errors....
*****************************************************************************************
vectr_ptr.cpp: In function `int main()':
vectr_ptr.cpp:6: `vector' undeclared (first use this function)
vectr_ptr.cpp:6: (Each undeclared identifier is reported only once for
each
function it appears in.)
vectr_ptr.cpp:6: syntax error before `>' token
vectr_ptr.cpp:11: `cout' undeclared (first use this function)
vectr_ptr.cpp:14: redeclaration of `int i'
vectr_ptr.cpp:7: `int i' previously declared here
vectr_ptr.cpp:14: declaration of `int i'
vectr_ptr.cpp:7: conflicts with previous declaration `int i'
*******************************************************************************************

can anybody please help me in compiling this code successfully and
explain me why am i getting these errors

Thanks...
 
O

onkar

also remove int in int i=10;
edu.mvk said:
i want to write a simple prog like below using vectors...

#include<vector>
using namespace std
int main()
{
vector<int> v;
int i,num;
for(i=0;i<10;i++)
{
num = i;
cout << num << " ";
// v.push_back( num );
}
int i=10;
cout << i;
}

But after compiling this code using "gcc" i am getting the following
errors....
****************************************************************************************
vectr_ptr.cpp:4: syntax error before `int'
vectr_ptr.cpp:15: syntax error before `<<' token

/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp&) [with _Tp = size_t]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:793: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__a' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: (Each undeclared
identifier is
reported only once for each function it appears in.)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__b' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 =
const
signed char*]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:805: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last2' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first2' undeclared
(first
use this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last1' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first1' undeclared
(first
use this function)

********************************************************************************************

i am getting the above errors only when i include this stmt in the code
:

" using namespace std "

if i remove the statement from the code, i'm getting the following
errors....
*****************************************************************************************
vectr_ptr.cpp: In function `int main()':
vectr_ptr.cpp:6: `vector' undeclared (first use this function)
vectr_ptr.cpp:6: (Each undeclared identifier is reported only once for
each
function it appears in.)
vectr_ptr.cpp:6: syntax error before `>' token
vectr_ptr.cpp:11: `cout' undeclared (first use this function)
vectr_ptr.cpp:14: redeclaration of `int i'
vectr_ptr.cpp:7: `int i' previously declared here
vectr_ptr.cpp:14: declaration of `int i'
vectr_ptr.cpp:7: conflicts with previous declaration `int i'
*******************************************************************************************

can anybody please help me in compiling this code successfully and
explain me why am i getting these errors

Thanks...
 
O

onkar

compile with g++
also remove int in int i=10;
edu.mvk said:
i want to write a simple prog like below using vectors...

#include<vector>
using namespace std
int main()
{
vector<int> v;
int i,num;
for(i=0;i<10;i++)
{
num = i;
cout << num << " ";
// v.push_back( num );
}
int i=10;
cout << i;
}

But after compiling this code using "gcc" i am getting the following
errors....
****************************************************************************************
vectr_ptr.cpp:4: syntax error before `int'
vectr_ptr.cpp:15: syntax error before `<<' token

/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp&) [with _Tp = size_t]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:793: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__a' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: (Each undeclared
identifier is
reported only once for each function it appears in.)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__b' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 =
const
signed char*]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:805: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last2' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first2' undeclared
(first
use this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last1' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first1' undeclared
(first
use this function)

********************************************************************************************

i am getting the above errors only when i include this stmt in the code
:

" using namespace std "

if i remove the statement from the code, i'm getting the following
errors....
*****************************************************************************************
vectr_ptr.cpp: In function `int main()':
vectr_ptr.cpp:6: `vector' undeclared (first use this function)
vectr_ptr.cpp:6: (Each undeclared identifier is reported only once for
each
function it appears in.)
vectr_ptr.cpp:6: syntax error before `>' token
vectr_ptr.cpp:11: `cout' undeclared (first use this function)
vectr_ptr.cpp:14: redeclaration of `int i'
vectr_ptr.cpp:7: `int i' previously declared here
vectr_ptr.cpp:14: declaration of `int i'
vectr_ptr.cpp:7: conflicts with previous declaration `int i'
*******************************************************************************************

can anybody please help me in compiling this code successfully and
explain me why am i getting these errors

Thanks...
 
V

Vig

I'm out of touch with programming at this level I guess here, but
semicolon after 'using namespace std' may help? Let me get gcc compiler
on my machine...

Cheers!
--
Vig said:
compile with g++
also remove int in int i=10;
edu.mvk said:
i want to write a simple prog like below using vectors...

#include<vector>
using namespace std
int main()
{
vector<int> v;
int i,num;
for(i=0;i<10;i++)
{
num = i;
cout << num << " ";
// v.push_back( num );
}
int i=10;
cout << i;
}

But after compiling this code using "gcc" i am getting the following
errors....
****************************************************************************************
vectr_ptr.cpp:4: syntax error before `int'
vectr_ptr.cpp:15: syntax error before `<<' token

/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp&) [with _Tp = size_t]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:793: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__a' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: (Each undeclared
identifier is
reported only once for each function it appears in.)
/usr/include/c++/3.2.3/bits/stl_algobase.h:153: `__b' undeclared (first
use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 =
const
signed char*]':
/usr/include/c++/3.2.3/bits/stl_algobase.h:805: instantiated from
here
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last2' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first2' undeclared
(first
use this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__last1' undeclared
(first use
this function)
/usr/include/c++/3.2.3/bits/stl_algobase.h:745: `__first1' undeclared
(first
use this function)

********************************************************************************************

i am getting the above errors only when i include this stmt in the code
:

" using namespace std "

if i remove the statement from the code, i'm getting the following
errors....
*****************************************************************************************
vectr_ptr.cpp: In function `int main()':
vectr_ptr.cpp:6: `vector' undeclared (first use this function)
vectr_ptr.cpp:6: (Each undeclared identifier is reported only once for
each
function it appears in.)
vectr_ptr.cpp:6: syntax error before `>' token
vectr_ptr.cpp:11: `cout' undeclared (first use this function)
vectr_ptr.cpp:14: redeclaration of `int i'
vectr_ptr.cpp:7: `int i' previously declared here
vectr_ptr.cpp:14: declaration of `int i'
vectr_ptr.cpp:7: conflicts with previous declaration `int i'
*******************************************************************************************

can anybody please help me in compiling this code successfully and
explain me why am i getting these errors

Thanks...
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top