2012-02-05 15 views
2

我在編譯VC++ 2010下面的代碼是一個家庭作業:32錯誤的東西,不應該發生

#include <iostream> 
#include <map> 
#include "PaintJobEst.h" 

using namespace std; 

int main(void) 
{ 
    map< string, double > data; 

    double numRooms = 0, costPerGallon = 0, sqrFtWallSpace = 0; 

    cout << "How many rooms wil you be painting today? " << endl; 
    cin >> numRooms; 

    const bool numRoomsAtLeastOne = (numRooms >= 1); 

    if (!numRoomsAtLeastOne) 
    { 
     cout << "INVALID ENTRY: Please enter a value greater than or equal to 1 for the amount of rooms you wish to paint" << endl; 
     main(); 
    } 

    cout << "What is the cost of paint per gallon? " << endl; 
    cin >> costPerGallon; 

    const bool costCheck = (costPerGallon >= 10.00); 

    if (!costCheck) 
    { 
     cout << "INVALID ENTRY: Please enter a value greater than or equal to 10.00 for the cost-per-gallon of paint you wish to use." << endl; 
     main(); 
    } 

    cout << "What is the square feet of wallspace per gallon of paint you wish to cover? " << endl; 
    cin >> sqrFtWallSpace; 

    const bool sqrFeetCheck = (sqrFtWallSpace >= 0); 

    if (!sqrFeetCheck) 
    { 
     cout << "INVALID ENTRY: Please enter a value which is NON-NEGATIVE for covering the square feet of wallspace per gallon" << endl; 
     main(); 
    } 

    data.insert(pair< string, double >("numRooms", numRooms)); 
    data.insert(pair< string, double >("costPerGallon", costPerGallon)); 
    data.insert(pair< string, double >("sqrFtWallSpace", sqrFtWallSpace)); 

    Estimate(data); 

    system("pause"); 

} 

然而,當我編譯它,不然我和奇怪的錯誤淹沒這是有關如何xfunctional文件。爲什麼發生這種情況,我不知道。我是否在某處丟失了包含文件?

錯誤

>------ Build started: Project: Project17, Configuration: Debug Win32 ------ 
1> main.cpp 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator()(const _Ty &,const _Ty &) const' 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled 
1>   with 
1>   [ 
1>    _Kty=std::string, 
1>    _Ty=double, 
1>    _Pr=std::less<std::string>, 
1>    _Alloc=std::allocator<std::pair<const std::string,double>>, 
1>    _Mfl=false 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\users\holland\documents\code\projects\studying\chapter6\project17\project17\main.cpp(13) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled 
1>   with 
1>   [ 
1>    _Kty=std::string, 
1>    _Ty=double 
1>   ] 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator 
1> PaintJobEst.cpp 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <' 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator()(const _Ty &,const _Ty &) const' 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled 
1>   with 
1>   [ 
1>    _Kty=std::string, 
1>    _Ty=double, 
1>    _Pr=std::less<std::string>, 
1>    _Alloc=std::allocator<std::pair<const std::string,double>>, 
1>    _Mfl=false 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled 
1>   with 
1>   [ 
1>    _Traits=std::_Tmap_traits<std::string,double,std::less<std::string>,std::allocator<std::pair<const std::string,double>>,false> 
1>   ] 
1>   c:\users\holland\documents\code\projects\studying\chapter6\project17\project17\paintjobest.cpp(9) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled 
1>   with 
1>   [ 
1>    _Kty=std::string, 
1>    _Ty=double 
1>   ] 
+3

添加頭如下描述:http://stackoverflow.com/questions/4939204/使用-AN-stdstring作爲一種密鑰換一個-stdmap – Maggie 2012-02-05 04:04:51

回答

7

添加#include <string>和問題解決了,我在VC++ 2010