Cygwin vector problem

Discussion in 'C++' started by Vish, Dec 4, 2003.

  1. Vish

    Vish Guest

    I cannot compile a simple code as below using cygwin. I believe I am
    using latest version of g++(3.3.1) I get following error

    is_equal.cpp:9:19: ccc.cpp: No such file or directory
    is_equal.cpp:11: error: `vector' was not declared in this scope
    is_equal.cpp:11: error: parse error before `>' token
    is_equal.cpp: In function `bool equal_vec(...)':
    is_equal.cpp:12: error: `a' undeclared (first use this function)
    is_equal.cpp:12: error: (Each undeclared identifier is reported only
    once for
    each function it appears in.)
    is_equal.cpp:12: error: `b' undeclared (first use this function)
    is_equal.cpp: In function `int main()':
    is_equal.cpp:23: error: `vector' undeclared (first use this function)
    is_equal.cpp:23: error: parse error before `>' token
    is_equal.cpp:25: error: `cout' undeclared (first use this function)
    is_equal.cpp:26: error: `cin' undeclared (first use this function)
    is_equal.cpp:36: error: `v1' undeclared (first use this function)
    is_equal.cpp:46: error: parse error before `>' token
    is_equal.cpp:57: error: `v2' undeclared (first use this function)
    is_equal.cpp:74:2: warning: no newline at end of file


    /*
    Vishal Pahuja
    Lab 9 part 3
    */

    #include <iostream>
    #include <vector>
    #include <stdexcept>


    bool equal_vec(vector<int> a, vector<int> b)
    { if (a.size() !=b.size()) return false;
    for (int i = 0;i<a.size();i++)
    {
    if (a != b) return false;
    }
    return true;
    }


    int main()

    { vector<int> v1;
    int v1size;
    cout << "\nHow many value you want to enter for vector v1?: \n";
    cin >>v1size;

    cout << "\nEnter values for vector v1: \n";
    int i,j;

    for (i = 0; i < v1size; i++)
    {
    cout << "Next: ";
    //cin >> v1;
    cin >> j;
    v1.push_back(j);
    }
    cout << "\nVector v1 :\n";
    for (i = 0; i < v1.size(); i++)
    {
    cout << v1
    << "\n";
    }


    vector<int> v2;
    int v2size;
    cout << "\nHow many value you want to enter for vector v2?: \n";
    cin>>v2size;

    cout << "\nEnter values for vector v2: \n";
    for (i = 0; i < v2size; i++)
    {
    cout << "Next: ";
    //cin >> v2;
    cin >> j;
    v2.push_back(j);
    }

    cout << "\nVector v2 :\n";
    for (i= 0; i< v2.size(); i++)
    {
    cout << v2
    << "\n";
    }

    bool isequal;
    isequal=equal_vec(v1,v2);

    if (isequal) cout<< "The vectors are equal\n";
    else cout<< "The vectors are not equal\n";


    }
    Vish, Dec 4, 2003
    #1
    1. Advertising

  2. Vish

    Xenos Guest

    "Vish" <> wrote in message
    news:...
    > I cannot compile a simple code as below using cygwin. I believe I am
    > using latest version of g++(3.3.1) I get following error
    >
    > is_equal.cpp:9:19: ccc.cpp: No such file or directory
    > is_equal.cpp:11: error: `vector' was not declared in this scope
    > is_equal.cpp:11: error: parse error before `>' token
    > is_equal.cpp: In function `bool equal_vec(...)':
    > is_equal.cpp:12: error: `a' undeclared (first use this function)
    > is_equal.cpp:12: error: (Each undeclared identifier is reported only
    > once for
    > each function it appears in.)
    > is_equal.cpp:12: error: `b' undeclared (first use this function)
    > is_equal.cpp: In function `int main()':
    > is_equal.cpp:23: error: `vector' undeclared (first use this function)
    > is_equal.cpp:23: error: parse error before `>' token
    > is_equal.cpp:25: error: `cout' undeclared (first use this function)
    > is_equal.cpp:26: error: `cin' undeclared (first use this function)
    > is_equal.cpp:36: error: `v1' undeclared (first use this function)
    > is_equal.cpp:46: error: parse error before `>' token
    > is_equal.cpp:57: error: `v2' undeclared (first use this function)
    > is_equal.cpp:74:2: warning: no newline at end of file
    >
    >
    > /*
    > Vishal Pahuja
    > Lab 9 part 3
    > */
    >
    > #include <iostream>
    > #include <vector>
    > #include <stdexcept>
    >
    >
    > bool equal_vec(vector<int> a, vector<int> b)
    > { if (a.size() !=b.size()) return false;
    > for (int i = 0;i<a.size();i++)
    > {
    > if (a != b) return false;
    > }
    > return true;
    > }
    >
    >
    > int main()
    >
    > { vector<int> v1;
    > int v1size;
    > cout << "\nHow many value you want to enter for vector v1?: \n";
    > cin >>v1size;
    >
    > cout << "\nEnter values for vector v1: \n";
    > int i,j;
    >
    > for (i = 0; i < v1size; i++)
    > {
    > cout << "Next: ";
    > //cin >> v1;
    > cin >> j;
    > v1.push_back(j);
    > }
    > cout << "\nVector v1 :\n";
    > for (i = 0; i < v1.size(); i++)
    > {
    > cout << v1
    > << "\n";
    > }
    >
    >
    > vector<int> v2;
    > int v2size;
    > cout << "\nHow many value you want to enter for vector v2?: \n";
    > cin>>v2size;
    >
    > cout << "\nEnter values for vector v2: \n";
    > for (i = 0; i < v2size; i++)
    > {
    > cout << "Next: ";
    > //cin >> v2;
    > cin >> j;
    > v2.push_back(j);
    > }
    >
    > cout << "\nVector v2 :\n";
    > for (i= 0; i< v2.size(); i++)
    > {
    > cout << v2
    > << "\n";
    > }
    >
    > bool isequal;
    > isequal=equal_vec(v1,v2);
    >
    > if (isequal) cout<< "The vectors are equal\n";
    > else cout<< "The vectors are not equal\n";
    >
    >
    > }


    you need to qualify all declarations from the c++ stardard headers with
    "std::" or add the line "using namespace std;" before using them.
    Xenos, Dec 4, 2003
    #2
    1. Advertising

  3. Vish

    red floyd Guest

    Vish wrote:
    > I cannot compile a simple code as below using cygwin. I believe I am
    > using latest version of g++(3.3.1) I get following error
    >
    > is_equal.cpp:9:19: ccc.cpp: No such file or directory
    > is_equal.cpp:11: error: `vector' was not declared in this scope
    > is_equal.cpp:11: error: parse error before `>' token
    > is_equal.cpp: In function `bool equal_vec(...)':
    > is_equal.cpp:12: error: `a' undeclared (first use this function)
    > is_equal.cpp:12: error: (Each undeclared identifier is reported only
    > once for
    > each function it appears in.)
    > is_equal.cpp:12: error: `b' undeclared (first use this function)
    > is_equal.cpp: In function `int main()':
    > is_equal.cpp:23: error: `vector' undeclared (first use this function)
    > is_equal.cpp:23: error: parse error before `>' token
    > is_equal.cpp:25: error: `cout' undeclared (first use this function)
    > is_equal.cpp:26: error: `cin' undeclared (first use this function)
    > is_equal.cpp:36: error: `v1' undeclared (first use this function)
    > is_equal.cpp:46: error: parse error before `>' token
    > is_equal.cpp:57: error: `v2' undeclared (first use this function)
    > is_equal.cpp:74:2: warning: no newline at end of file
    >
    >
    > /*
    > Vishal Pahuja
    > Lab 9 part 3
    > */
    >
    > #include <iostream>
    > #include <vector>
    > #include <stdexcept>
    >
    >
    > bool equal_vec(vector<int> a, vector<int> b)
    > { if (a.size() !=b.size()) return false;
    > for (int i = 0;i<a.size();i++)
    > {
    > if (a != b) return false;
    > }
    > return true;
    > }
    >
    >
    > int main()
    >
    > { vector<int> v1;
    > int v1size;
    > cout << "\nHow many value you want to enter for vector v1?: \n";
    > cin >>v1size;
    >
    > cout << "\nEnter values for vector v1: \n";
    > int i,j;
    >
    > for (i = 0; i < v1size; i++)
    > {
    > cout << "Next: ";
    > //cin >> v1;
    > cin >> j;
    > v1.push_back(j);
    > }
    > cout << "\nVector v1 :\n";
    > for (i = 0; i < v1.size(); i++)
    > {
    > cout << v1
    > << "\n";
    > }
    >
    >
    > vector<int> v2;
    > int v2size;
    > cout << "\nHow many value you want to enter for vector v2?: \n";
    > cin>>v2size;
    >
    > cout << "\nEnter values for vector v2: \n";
    > for (i = 0; i < v2size; i++)
    > {
    > cout << "Next: ";
    > //cin >> v2;
    > cin >> j;
    > v2.push_back(j);
    > }
    >
    > cout << "\nVector v2 :\n";
    > for (i= 0; i< v2.size(); i++)
    > {
    > cout << v2
    > << "\n";
    > }
    >
    > bool isequal;
    > isequal=equal_vec(v1,v2);
    >
    > if (isequal) cout<< "The vectors are equal\n";
    > else cout<< "The vectors are not equal\n";
    >
    >
    > }


    vector is in the std namespace (as in cout). Put a "using namespace std;" after the includes
    red floyd, Dec 4, 2003
    #3
  4. Vish

    Vish Guest

    Wow. You guys rock....

    Thanks. using namespace was the trick. I wonder why we were not told to use
    it in out class. In class they always said, its your sweet will if you want
    to say using namespace std. Well, Now I know...

    Thanks again
    Vish, Dec 5, 2003
    #4
  5. Vish

    red floyd Guest

    Vish wrote:
    > Wow. You guys rock....
    >
    > Thanks. using namespace was the trick. I wonder why we were not told to use
    > it in out class. In class they always said, its your sweet will if you want
    > to say using namespace std. Well, Now I know...
    >
    > Thanks again


    You shouldn't put a using directive in a HEADER file. In a source file, after
    all the includes, it shouldn't be a problem. Putting it in a header file can
    seriously confuse the compiler.


    Alternatively you could have said std::vector, std::cin, and std::cout
    red floyd, Dec 6, 2003
    #5
    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. Replies:
    0
    Views:
    430
  2. Replies:
    0
    Views:
    429
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    512
    Robin Becker
    Sep 5, 2003
  4. Replies:
    0
    Views:
    413
  5. Replies:
    8
    Views:
    1,915
    Csaba
    Feb 18, 2006
Loading...

Share This Page