CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Unhappy Question about overloading operator >> in STL.

    Hi, everyone!

    I meet with some trouble when debugging the following
    codes dealing with overloading operator >> in STL.
    I have tried my best to resolve it but still failed.
    My IDE is VC6.0.

    Source Codes:
    Code:
    --------
    #include <iostream>
    #include <map>
    #include <set>
    
    using namespace std;
    
    class employee_data {
    public:
    	employee_data() : name (""), skill(0), salary(0) {}
    	employee_data(string n, int s, long sa) : 
    	   name (n), skill (s), salary (sa) {}
    
    	string	name;
    	int 	skill;
    	long	salary;
    
       friend ostream& operator<< (ostream& os, const employee_data& e);
    };
    
    ostream& operator<< (ostream& os, const employee_data& e) {
    	os << "employee: " << e.name << " " << e.skill << " " << e.salary;
    	return os;
    }
    
    class employee {
    public: 
       employee (int i, employee_data e) :
          identification_code (i), description (e) {}
    
    	int identification_code;	// key expression to identify an employee
    	employee_data description;
    
    	bool operator< (const employee& e) const {
    	  return identification_code < e.identification_code; }
    };
    
    int main()
    {
    	set  <employee, less<employee> > employee_set;
    
    	multiset  <employee, less<employee> > employee_multiset;
    
    	employee_data ed1 ("john", 1, 5000);
    	employee_data ed2 ("tom", 5, 2000);
    	employee_data ed3 ("mary", 2, 3000);
    
    	employee e1 (1010, ed1); 
    	employee e2 (2020, ed2); 
    	employee e3 (3030, ed3); 
    
    	pair<set <employee, less<employee> >::iterator, bool>
    		result = employee_set.insert (e1);
    
    	if (result.second) cout << "insert ok"; else cout << "not inserted";
    	cout << endl << (*result.first).description.name << endl;
    
    	result = employee_set.insert (e1);
    	if (result.second) cout << "insert ok"; else cout << "not inserted";
    	
    	return 1;
    }
    --------
    Error messages:
    --------
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(22) : error C2679: binary '<<' : no operator

    defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class

    std::allocator<char> >' (or there is no acceptable conversion)
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(56) : error C2679: binary '<<' : no operator

    defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class

    std::allocator<
    char> >' (or there is no acceptable conversion)
    --------

    How to resolve them?


    Thanks in advance,
    George

    [Gabriel: added CODE tags]
    Last edited by Gabriel Fleseriu; February 20th, 2003 at 09:24 AM.

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    you forgot an include :

    Code:
    #include <string>

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Unhappy

    Thanks, Philip buddie!

    I have tried your method. There are no errors but several warning informations. I doubted why the length of characters
    is limited. Can you help?

    George
    --------
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(62) : warning C4786: 'std:air<std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee
    > >::iterator,std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::iterator>' : identifier was truncated to '255' characters in the debug information
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(62) : warning C4786: 'std:air<std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee
    > >::const_iterator,std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::const_iterator>' : identifier was truncated to '255' characters in the debug info
    rmation
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(62) : warning C4786: 'std:air<std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<emp
    loyee> >::iterator,std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::iterator>' : identifier was truncated to '255' characters in the debug inform
    ation
    C:\Program Files\Microsoft Visual Studio\MyProjects\testMap1\testMap1.cpp(62) : warning C4786: 'std:air<std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<emp
    loyee> >::const_iterator,std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::const_iterator>' : identifier was truncated to '255' characters in the
    debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(182) : warning C4786: 'std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::~_Tree<employee,em
    ployee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >' : identifier was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(182) : warning C4786: 'std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::~_Tree<employ
    ee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >' : identifier was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(162) : warning C4786: 'std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::_Tree<employee,emp
    loyee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >' : identifier was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__ehhandler$?insert@?$_Tree@Vemployee@@V1@U_Kfn@?$set@Vemployee@@U?$less@Vemployee@@@std@@V?$allocator@Vemployee@@@3@@std@@U?$less@Vemployee@@@4@V?$allocator@Vemploye
    e@@@4@@std@@QAE?AU?$pair@Viterator@?$_Tree@Vemployee@@V1@U_Kfn@?$set@Vemployee@@U?$less@Vemployee@@@std@@V?$allocator@Vemployee@@@3@@std@@U?$less@Vemployee@@@4@V?$allocator@Vemployee@@@4@@std@@_N@2@ABVemployee@@@Z' : identifier was truncated to '255
    ' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__unwindfunclet$?insert@?$_Tree@Vemployee@@V1@U_Kfn@?$set@Vemployee@@U?$less@Vemployee@@@std@@V?$allocator@Vemployee@@@3@@std@@U?$less@Vemployee@@@4@V?$allocator@Vemp
    loyee@@@4@@std@@QAE?AU?$pair@Viterator@?$_Tree@Vemployee@@V1@U_Kfn@?$set@Vemployee@@U?$less@Vemployee@@@std@@V?$allocator@Vemployee@@@3@@std@@U?$less@Vemployee@@@4@V?$allocator@Vemployee@@@4@@std@@_N@2@ABVemployee@@@Z$0' : identifier was truncated t
    o '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\xtree(162) : warning C4786: 'std::_Tree<employee,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::_Tree<employe
    e,employee,std::multiset<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >' : identifier was truncated to '255' characters in the debug information
    c:\program files\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std:air<std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::iterato
    r,bool>:air<std::_Tree<employee,employee,std::set<employee,std::less<employee>,std::allocator<employee> >::_Kfn,std::less<employee>,std::allocator<employee> >::iterator,bool>' : identifier was truncated to '255' characters in the debug information
    --------


    Originally posted by Philip Nicoletti
    you forgot an include :

    Code:
    #include <string>

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    That is a VC++ thing. I think that they got rid of
    these warnings in the latest version.

    You can disable them by putting this at the top
    of your code :

    Code:
    #pragma warning(disable:4786)

  5. #5
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    I just wanted to note that both of these questions have already
    been answered to George2 in an older post. This is why I get
    upset with the guy; he not only asks a superfluous number of
    questions ... but he asks them over and over....

    Here's a link to the older post to refresh your memory, George2:
    http://www.codeguru.com/forum/showth...hreadid=230206

    It wasn't really that long ago, either.

    --Paul

  6. #6
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    Thanks, Philip buddie!

    George

    Originally posted by Philip Nicoletti
    That is a VC++ thing. I think that they got rid of
    these warnings in the latest version.

    You can disable them by putting this at the top
    of your code :

    Code:
    #pragma warning(disable:4786)

  7. #7
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468
    I am really sorry, PaulWendt.

    Next time I will try my best, trust me!


    George

    Originally posted by PaulWendt
    I just wanted to note that both of these questions have already
    been answered to George2 in an older post. This is why I get
    upset with the guy; he not only asks a superfluous number of
    questions ... but he asks them over and over....

    Here's a link to the older post to refresh your memory, George2:
    http://www.codeguru.com/forum/showth...hreadid=230206

    It wasn't really that long ago, either.

    --Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured