I'm new here, this is my first post. In my programming class I am designing a simple text based video game. It's going very well, but I'm having trouble getting the game to display the contents of a vector. Pretty much, the user maneuvers through rooms. Every room has a treasure. There's a thief roaming around the map that steals treasure. WHen entering a room, the user has the option to pick up the treasure in the room and store it. I am implementing this via a vector, and having it store the name of the item in this vector. When the thief steals an item, the user has the option to view their inventory. To do this, I want to print the elements of the vector, but it keeps giving me the error :
1>c:\users\justin\documents\visual studio 2008\projects\room\room\adventureproject.cpp(170) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion) 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(700): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(738): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(785): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(909): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(916): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(923): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(930): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(170): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(176): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(183): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(190): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(210): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(243): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(263): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 int)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(288): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(308): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(328): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(349): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(369): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(390): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(410): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(430): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(450): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(470): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> while trying to match the argument list '(std::ostream, std::basic_string<_Elem,_Traits,_Ax>)' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char> 1> ]
which is extremely confusing. My code for this piece looks like
if(thiefIndex==roomIndex)
{
treasureList.pop_back();
cout<<" A thief has stolen some of your treasure!"<<endl;
cout<<" Would you like to view your inventory? (y/n) "<<endl;
cin>> choice;
switch (choice){
case 'y':
cout<<endl;
for( iter = treasureList.begin(); iter != treasureList.end(); iter++ ) {
cout << *iter << endl;
}
break;
case 'n':
cout<< " You scream obscenities as loud as you can."<<endl<<" No one hears you";
}
}
I have my iterator declared as vector<string>::iterator iter; in the declarations. Why won't it print out?
Any help is greatly appreciated!! J

New Topic/Question
Reply




MultiQuote




|