main.cpp
------------------------------------------
#include <string>
#include <vector>void main()
{
vector< string > iv1(4);
}
------------------------------------------
是VC的环境不对?还是……

解决方案 »

  1.   

    #include <string>
    #include <vector>
    using namespace std;
    void main()
    {
    vector< string > iv1(4);
    }
      

  2.   

    yes.,using namespace std;std::vector<string>
      

  3.   

    以下warning是什么意思?是否可以不理会?--------------------Configuration: Stack - Win32 Debug--------------------
    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)
      

  4.   

    消除这些警告可以用下面这个
    #pragma warning(disable:4786)
    让编译起来降低警告的级别!
      

  5.   

    #include <string>
    #include <vector>
    #pragma warning(disable:4786)
    using namespace std;
      

  6.   

    to arvid_gs(west):你的代码应该把#pragma行放在#include <vector>行之前,不然编译还是有warning,,对吧!
    --------------------------------------------------
    #include <string>
    #pragma warning(disable:4786)
    #include <vector>
    using namespace std;
      

  7.   

    你要安装STL,
    然后打开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”。
      

  8.   

    using namespace std;
    或#include <string.h>
     #include <vector.h>
    .h是C的习惯用法
    在C++中用using namespace std;
      

  9.   

    bluebohe(薄荷) 警告也不能忽视的,有些时候警告会比错误还另人头疼
      

  10.   

    to lkjx82(风化血)我用#include <string.h>后,有3个error(s)
    ----------------------------------------------------
    #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)
      

  11.   

    to: ppzcgg(排排坐,吃果果)怎么安装STL啊,哪里有安装程序啊,我在网上搜不到,是不是我装好STL,不用using namespace std;就可以编译通过了?
      

  12.   

    没人回答我就只有结帖了……akiko(弥弥)第一个回帖正确,但回得不详细,我这个新手不知道你这句话是什么意思,反而bluebohe(薄荷)写的我一看就明白,所以akiko(弥弥)得10。bluebohe(薄荷)得10。NewFree(新自由人) 也给了我一个差不多忘记了的知识点,得10。vcforever(霓裳羽衣)给了我一个新知识点,得10。ppzcgg(排排坐,吃果果)给的我不知道对不对,也没回来再给我解决问题,所以只好得5再次,多谢兄弟们!