没有加using namespace std;这句的时候 #include<iostream>  
#include<vector>  
#include<string>  string pooh_pals[] = {  
"tigger","pigger"  
};  int main(){  
vector<string> pp(pooh_pals,pooh_pals+2);  
vector<string>::iterator iter= pp.begin();  
vector<string>::iterator iter_end = pp.end();  cout << "these are pp's data: ";  
for( ; iter!=iter_end; iter++ )  
{  
cout << *iter << endl;  
}  
return 0;  
}  编译的时候报下面的错误:  
Compiling...  
f1.cpp  
d:\vc\protest\f1.cpp(5) : error C2146: syntax error : missing ';' before identifier 'pooh_pals'  
d:\vc\protest\f1.cpp(5) : error C2501: 'string' : missing storage-class or type specifiers  
d:\vc\protest\f1.cpp(5) : fatal error C1004: unexpected end of file found  
Error executing cl.exe.  f1.obj - 3 error(s), 0 warning(s)  如果加上using namespace std;后编译的时候报下面的错误:  Compiling...  
f1.cpp  
D:\vc\proTest\f1.cpp(21) : 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<char,std::char_trait  
s<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  
D:\vc\proTest\f1.cpp(21) : 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  
c:\program files\microsoft visual studio\vc98\include\vector(56) : 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<char,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  
c:\program files\microsoft visual studio\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<char,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  f1.obj - 0 error(s), 4 warning(s)

解决方案 »

  1.   

    没加的时候,找不到string的定义
      

  2.   

    可能是你编译器 对STL的支持有问题,我这边编译第二个没有warning的。
      

  3.   

    运行结果没问题,可是我还是弄不明白warning是怎么回事?另外STL是???
      

  4.   

    加上后出现问题很正常啊
    因为在编译的时候,其实是要将STL中类的名字进行展开的展开得到全名了,会太长,所以说就会将这个类的名字给截短.即identifier was truncated to '255' characters
    一般不用担心.
      

  5.   

    不影响结果的话
    warning可以不用管它..
      

  6.   

    呵呵,多谢几位大侠的指点,刚才去查了STL,才知道是什么意思:)
      

  7.   

    identifier was truncated to '255' characters in the debug information应该是提示你会把string的内容截取到最大255