这段代码就是模仿书上写的。但是就是编译通不过,一大堆编译错误,编译错误如下:
1>------ Build started: Project: DialogTest, Configuration: Debug Win32 ------
1>Compiling...
1>DialogTestDlg.cpp
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xtree(1466) : see declaration of 'std::operator <'
1> c:/program files/microsoft visual studio 9.0/vc/include/functional(142) : 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/microsoft visual studio 9.0/vc/include/map(68) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1> with
1> [
1> _Ty=std::string
1> ]
1> c:/program files/microsoft visual studio 9.0/vc/include/xtree(22) : 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=std::string,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,std::string>>,
1> _Mfl=true
1> ]
1> c:/program files/microsoft visual studio 9.0/vc/include/xtree(63) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,true>
1> ]
1> c:/program files/microsoft visual studio 9.0/vc/include/xtree(89) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,true>
1> ]
1> c:/program files/microsoft visual studio 9.0/vc/include/xtree(107) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,true>
1> ]
1> c:/program files/microsoft visual studio 9.0/vc/include/map(203) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,true>
1> ]
1> c:/documents and settings/admin/デスクトップ/vs 2008 test/dialogtest/dialogtest/dialogtestdlg.cpp(166) : see reference to class template instantiation 'std::multimap<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=std::string
1> ]
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xtree(1466) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xtree(1466) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xtree(1466) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/queue(107) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/queue(107) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/queue(107) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/queue(107) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::stack<_Ty,_Container> &,const std::stack<_Ty,_Container> &)' : could not deduce template argument for 'const std::stack<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/stack(94) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::stack<_Ty,_Container> &,const std::stack<_Ty,_Container> &)' : could not deduce template argument for 'const std::stack<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/stack(94) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::stack<_Ty,_Container> &,const std::stack<_Ty,_Container> &)' : could not deduce template argument for 'const std::stack<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/stack(94) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::stack<_Ty,_Container> &,const std::stack<_Ty,_Container> &)' : could not deduce template argument for 'const std::stack<_Ty,_Container> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/stack(94) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/deque(1354) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/deque(1354) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/deque(1354) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/deque(1354) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/vector(1320) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/vector(1320) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/vector(1320) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1> c:/program files/microsoft visual studio 9.0/vc/include/vector(1320) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2236) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2236) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2236) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2236) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2046) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2046) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2046) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/xutility(2046) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/utility(84) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/utility(84) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/utility(84) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : 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/microsoft visual studio 9.0/vc/include/utility(84) : see declaration of 'std::operator <'
1>c:/program files/microsoft visual studio 9.0/vc/include/functional(143) : error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>Build log was saved at "file://c:/Documents and Settings/Admin/デスクトップ/VS 2008 TEST/DialogTest/DialogTest/Debug/BuildLog.htm"
1>DialogTest - 33 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
看的我头大啊。。哪么简单的几句话,怎么可能有那么多错误呐。经过google(goolge真是好东西啊),原来是没有#include<string>的问题。以前一直认为有了#include<iostream>就不用#include<string>了呐。问题解决以后,为了弄懂为什么,就再次google(再次赞美一下,google真nice),发现如下结论:
1,<string>是包装了std的C++头文件,对应的是新的strng类.
2,<iostream>是包含输入/输出流处理的头文件.
iostream.h是包含输入/输出流处理的头文件,iostream就什么都不是了
但用iostream要加名词空间namespace
#include<iostream.h>
或者是
#include<iostream>
using namespace std;
二者都行
#include<iostream.h>是C语言中比较通用的
#include<iostream>
using namespace std;
是C++中比较通用的