S
sd2004
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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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: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: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: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: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: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: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: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: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
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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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>: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: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: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: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: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: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: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: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: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