STL ??

Discussion in 'C++' started by sd2004, Jan 25, 2006.

  1. sd2004

    sd2004 Guest

    could someone please explain to me why I am getting compiling error on
    line 69 ?
    do I need to use push_back to store data ?
    Thanks,

    ///////////////////////////// source code ////////////////
    #include<iostream>
    #include <string>
    #include<vector>
    #include<sstream>
    #include<fstream>
    #include<numeric>
    using namespace std;

    class dog_info_class
    {
    public:
    string name;
    int id;
    int YearBorn;
    string type;
    int dog_age(const int year);
    };


    #define goldenretriever 11
    #define Lab 33
    #define Boxer 44
    #define Terrier 55
    int const CurrentYear =2006;

    int main()
    {
    vector<dog_info_class> v;

    dog_info_class dog;

    ifstream in ("test5g.txt");
    string line;
    while (!getline(in,line).eof()){
    if (line.find("#")!=std::string::npos)continue;
    istringstream is(line);
    if(is>>dog.name>>dog.id>>dog.YearBorn>>dog.type)
    {
    v.push_back(dog);
    }
    }
    vector<dog_info_class>::iterator iter;
    for (iter=v.begin();iter!=v.end();++iter){
    int results;
    switch (iter->id){
    case goldenretriever:
    results=dog.dog_age(iter->YearBorn);
    cout << "AGE IS " << results <<endl;
    break;
    case Lab:
    results=dog.dog_age(iter->YearBorn);
    cout << " AGE IS: "<< results<<endl;
    break;
    case Boxer:
    results=dog.dog_age(iter->YearBorn);
    cout << " AGE IS: "<< results<<endl;
    break;
    case Terrier:
    results=dog.dog_age(iter->YearBorn);
    cout << " AGE IS: "<< results<<endl;
    break;
    default:
    break;
    }

    }
    vector<dog_info_class>::iterator Iter;
    for (Iter=v.begin();Iter!=v.end();++Iter){
    cout << Iter->dog_age <<endl; // Line 69 ,compiling error here
    // cout << Iter->name <<endl; // OK here
    }

    return 0;

    }
    int dog_info_class::dog_age (const int YearBorn){
    int age = (CurrentYear - YearBorn)*2;
    return age;
    }

    ////////////// ERROR message //////////////////////



    bash-2.05b$ g++ test5g.cpp
    test5g.cpp: In function `int main()':
    test5g.cpp:69: error: no match for 'operator<<' in 'std::cout <<
    (&Iter)->__gnu_cxx::__normal_iterator<_Iterator,
    _Container>::eek:perator->
    [with _Iterator = dog_info_class*, _Container =
    std::vector<dog_info_class,
    std::allocator<dog_info_class> >]()->dog_age'
    /usr/include/c++/3.3.3/bits/ostream.tcc:63: error: candidates are:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(std::basic_ostream<_CharT,
    _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT =
    char,
    _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:74: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(std::basic_ios<_CharT,
    _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
    _Traits

    = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:86: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT
    = char,

    _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:122: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(long int) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:156: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(long unsigned int) [with _CharT = char, _Traits
    =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:98: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(bool) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:178: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(short int) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:189: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(short unsigned int) [with _CharT = char,
    _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:193: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(int) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:204: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(unsigned int) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:181: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(long long int) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:216: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(long long unsigned int) [with _CharT = char,
    _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:241: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(double) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:219: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(float) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:265: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(long double) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:289: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(const void*) [with _CharT = char, _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:313: error:
    std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
    _Traits>::eek:perator<<(std::basic_streambuf<_CharT, _Traits>*) [with
    _CharT =
    char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:436: error:
    std::basic_ostream<_CharT, _Traits>&
    std::eek:perator<<(std::basic_ostream<_CharT, _Traits>&, char) [with
    _CharT =
    char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:512: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, char) [with _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:447: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, signed char) [with _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:452: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, unsigned char) [with _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:572: error:
    std::basic_ostream<_CharT, _Traits>&
    std::eek:perator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
    [with
    _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/bits/ostream.tcc:616: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, const char*) [with _Traits = std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:486: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, const signed char*) [with _Traits =
    std::char_traits<char>]
    /usr/include/c++/3.3.3/ostream:491: error:
    std::basic_ostream<char, _Traits>&
    std::eek:perator<<(std::basic_ostream<char,
    _Traits>&, const unsigned char*) [with _Traits =
    std::char_traits<char>]
    bash-2.05b$

    ///////////// input file "test5g.txt" //////////

    ########################################
    #Name ID YearBorn Type
    ########################################
    Cricket 11 2000 GoldenRetriever
    Nitro 11 2005 GoldenRetriever
    Maxtor 33 2004 Lab
    Arron 44 2001 Boxer
    #Arron 54 2002 Boxer
    Dora 55 2000 Terrier
    sd2004, Jan 25, 2006
    #1
    1. Advertising

  2. sd2004 wrote:
    > could someone please explain to me why I am getting compiling error on
    > line 69 ?
    > do I need to use push_back to store data ?
    > [..]
    > vector<dog_info_class>::iterator Iter;
    > for (Iter=v.begin();Iter!=v.end();++Iter){
    > cout << Iter->dog_age <<endl; // Line 69 ,compiling error here


    When calling a function you need to supply arguments. If no arguments
    are needed, you still need to supply parentheses:

    cout << Iter->dog_age() << endl;

    > // cout << Iter->name <<endl; // OK here
    > }
    > [...]


    V
    Victor Bazarov, Jan 25, 2006
    #2
    1. Advertising

  3. sd2004

    sd2004 Guest

    Thanks, I am learning through my mistake.
    Again , I really appreciate for your time and help.
    sd2004, Jan 25, 2006
    #3
    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. Allan Bruce

    To STL or not to STL

    Allan Bruce, Oct 16, 2003, in forum: C++
    Replies:
    41
    Views:
    1,044
    Christopher Benson-Manica
    Oct 17, 2003
  2. Replies:
    4
    Views:
    799
    Daniel T.
    Feb 16, 2006
  3. Replies:
    2
    Views:
    553
    klaus hoffmann
    Feb 22, 2006
  4. Replies:
    5
    Views:
    503
    Markus Schoder
    Apr 16, 2006
  5. Steve
    Replies:
    2
    Views:
    503
    Andre Kostur
    Nov 6, 2007
Loading...

Share This Page