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

Discussion in 'C++' started by edu.mvk, Jul 8, 2006.

  1. edu.mvk

    edu.mvk Guest

    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...
     
    edu.mvk, Jul 8, 2006
    #1
    1. Advertisements

  2. edu.mvk

    onkar Guest

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



     
    onkar, Jul 8, 2006
    #2
    1. Advertisements

  3. edu.mvk

    onkar Guest

    also remove int in int i=10;
     
    onkar, Jul 8, 2006
    #3
  4. edu.mvk

    onkar Guest

    compile with g++
     
    onkar, Jul 8, 2006
    #4
  5. edu.mvk

    Ian Collins Guest

    Please don't top post.
     
    Ian Collins, Jul 8, 2006
    #5
  6. edu.mvk

    Vig Guest

    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, Jul 8, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.