📄 subject_25212.htm
字号:
<p>
序号:25212 发表者:brown 发表日期:2002-12-19 18:04:33
<br>主题:VC++ 遇到 C++ 的標準程式庫 vector, string 時有錯!!!
<br>内容:請問各位前輩,<BR>遇到一個問題<BR><BR>#include <vector><BR>#include <string><BR>vector<string> strAddress;<BR><BR><BR>出現 error message<BR>error C2143: syntax error : missing ';' before '<'<BR>error C2501: 'vector' : missing storage-class or type specifiers<BR>error C2143: syntax error : missing ';' before '<'<BR><BR>語法都沒錯,怎麼會如此?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:Vincent 回复日期:2002-12-19 20:11:50
<br>内容:應該是語法錯誤﹐vector是不是頭文件﹐是頭文件應該是<BR>#include <vector.h><BR>#include <string.h><BR>vector<string> strAddress;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:陳章民 回复日期:2002-12-19 22:35:49
<br>内容:vector<string> strAddress;<BR><BR>應該改成std::vector<string> strAddress;<BR><BR>或加入using namespace std;<BR><BR>名稱空間沒定義好吧!!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:brown 回复日期:2002-12-20 10:02:15
<br>内容:還是不行<BR>如果改成std::vector<string> strAddress;<BR>原始程式<BR>// 2.cpp : Defines the entry point for the console application.<BR>//<BR><BR>#include "stdafx.h"<BR>#include <vector><BR>#include <string><BR>//using namespace std;<BR>int main(int argc, char* argv[])<BR>{<BR> std::vector<string> strAddress;<BR> return 0;<BR>}<BR><BR>結果<BR>--------------------Configuration: 2 - Win32 Debug--------------------<BR>Compiling...<BR>2.cpp<BR>D:\TempB\2\2.cpp(13) : error C2065: 'string' : undeclared identifier<BR>D:\TempB\2\2.cpp(13) : error C2955: 'vector' : use of class template requires template argument list<BR> c:\program files\microsoft visual studio\vc98\include\vector(244) : see declaration of 'vector'<BR>D:\TempB\2\2.cpp(13) : error C2133: 'strAddress' : unknown size<BR>D:\TempB\2\2.cpp(13) : error C2512: 'vector' : no appropriate default constructor available<BR>D:\TempB\2\2.cpp(13) : error C2262: 'strAddress' : cannot be destroyed<BR>Error executing cl.exe.<BR><BR>2.exe - 5 error(s), 0 warning(s)<BR><BR>如果採 using namespace std;<BR><BR>原始程式<BR>// 2.cpp : Defines the entry point for the console application.<BR>//<BR><BR>#include "stdafx.h"<BR><BR>#include <vector><BR>#include <string><BR>using namespace std;<BR><BR><BR>int main(int argc, char* argv[])<BR>{<BR> vector<string> strAddress;<BR><BR> return 0;<BR>}<BR>則會有 warning 如下<BR><BR>Compiling...<BR>2.cpp<BR>D:\TempB\2\2.cpp(16) : 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_traits<ch<BR>ar>,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<BR>D:\TempB\2\2.cpp(16) : 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>,st<BR>d::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information<BR>c:\program files\microsoft visual studio\vc98\include\vector(39) : 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> > ><BR> >::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<BR>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> > ><BR> >::~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<BR>Linking...<BR><BR>2.exe - 0 error(s), 4 warning(s)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:陳章民 回复日期:2002-12-21 01:05:53
<br>内容:vector<string> strAddress;<BR>string宣告錯誤,若改成char即可..<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:brown 回复日期:2002-12-21 15:33:16
<br>内容:vector<string> strAddress;<BR><BR>在 compile 時選用 release.<BR>便 0 error, 0 warning
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -