main.cpp
------------------------------------------
#include <string>
#include <vector>void main()
{
vector< string > iv1(4);
}
------------------------------------------
是VC的环境不对?还是……
------------------------------------------
#include <string>
#include <vector>void main()
{
vector< string > iv1(4);
}
------------------------------------------
是VC的环境不对?还是……
#include <vector>
using namespace std;
void main()
{
vector< string > iv1(4);
}
Compiling...
main.cpp
e:\pf\vs\vc98\include\vector(48) : warning C4786: '??0?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QAE@IABV?$basic_string@DU?$char_traits@D
@std@@V?$allocator@D@2@@1@ABV?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@1@@Z' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
e:\pf\vs\vc98\include\vector(61) : warning C4786: '??0?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QAE@PBV?$basic_string@DU?$char_traits@D@
std@@V?$allocator@D@2@@1@0ABV?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@1@@Z' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
e:\pf\vs\vc98\include\vector(103) : warning C4786: '?rbegin@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QAE?AV?$reverse_iterator@PAV?$basi
c_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@AAV12@PAV12@H@2@XZ' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
e:\pf\vs\vc98\include\vector(105) : warning C4786: '?rbegin@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QBE?AV?$reverse_iterator@PBV?$basi
c_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@ABV12@PBV12@H@2@XZ' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
e:\pf\vs\vc98\include\vector(107) : warning C4786: '?rend@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QAE?AV?$reverse_iterator@PAV?$basic_
string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@AAV12@PAV12@H@2@XZ' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
e:\pf\vs\vc98\include\vector(108) : warning C4786: '?rend@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QBE?AV?$reverse_iterator@PBV?$basic_
string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@ABV12@PBV12@H@2@XZ' : identifier was truncated to '255' characters in the browser information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(9) : see reference to class template instantiation 'std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,
struct std::char_traits<char>,class std::allocator<char> > > >' being compiled
F:\xlee\SourceCode\_VC6\Stack\main.cpp(11) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<ch
ar,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
F:\xlee\SourceCode\_VC6\Stack\main.cpp(11) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std
::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
e:\pf\vs\vc98\include\vector(47) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<cha
r,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
e:\pf\vs\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string<ch
ar,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug informationmain.obj - 0 error(s), 10 warning(s)
#pragma warning(disable:4786)
让编译起来降低警告的级别!
#include <vector>
#pragma warning(disable:4786)
using namespace std;
--------------------------------------------------
#include <string>
#pragma warning(disable:4786)
#include <vector>
using namespace std;
然后打开VC++6.0,执行:tools->options,选择Directories栏,将D:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\INCLUDE\STLPORT加入到“include files”中,并保证在D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE前,从而是STL的头文件被优先使用。
注意:使用STL的工程必须设定:Project->settings,然后选择C/C++选项,再选择Code Generation,在use real-time library栏中选择“Debug Multithreaded DLL”或“Multithreaded DLL”。
或#include <string.h>
#include <vector.h>
.h是C的习惯用法
在C++中用using namespace std;
----------------------------------------------------
#include <string.h>void main()
{
string a;
}
----------------------------------------------------
--------------------Configuration: test_bi - Win32 Debug--------------------
Compiling...
main.cpp
F:\xlee\SourceCode\_VC6\test_bi\main.cpp(8) : error C2065: 'string' : undeclared identifier
F:\xlee\SourceCode\_VC6\test_bi\main.cpp(8) : error C2146: syntax error : missing ';' before identifier 'a'
F:\xlee\SourceCode\_VC6\test_bi\main.cpp(8) : error C2065: 'a' : undeclared identifier
Error executing cl.exe.test_bi.exe - 3 error(s), 0 warning(s)