📄 subject_62433.htm
字号:
<p>
序号:62433 发表者:ljl 发表日期:2003-11-26 18:58:40
<br>主题:请大家看看这段小程序的错误如何改正?
<br>内容:#include <iostream><BR>#include <string><BR>#include <vector><BR>#include <ctype.h><BR>using namespace std;<BR><BR>int main( int argc, char *argv[])<BR>{<BR> string ofile;<BR> vector<string, allocator> file_names;<BR><BR> char *pchar = "hello,world";<BR> file_names.push_back(string(pchar));<BR> <BR> return 0;<BR>}<BR><BR><BR>----------------------------------------------------------------------<BR>--------------------Configuration: page310 - Win32 Debug--------------------<BR>Compiling...<BR>page310.cpp<BR>F:\ljl\cppprimer\page310.cpp(10) : error C2955: 'allocator' : use of class template requires template argument list<BR> e:\program files xp\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'<BR>F:\ljl\cppprimer\page310.cpp(10) : error C2133: 'file_names' : unknown size<BR>F:\ljl\cppprimer\page310.cpp(10) : error C2512: 'vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator>' : no appropriate default constructor available<BR>F:\ljl\cppprimer\page310.cpp(10) : error C2262: 'file_names' : cannot be destroyed<BR>F:\ljl\cppprimer\page310.cpp(13) : error C2662: 'push_back' : cannot convert 'this' pointer from 'class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator>' to 'class std::vector<<BR>_Ty,_A> &'<BR> Reason: cannot convert from 'class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator>' to 'class std::vector<_Ty,_A>'<BR> Conversion requires a second user-defined-conversion operator or constructor<BR>Error executing cl.exe.<BR><BR>page310.obj - 5 error(s), 0 warning(s)
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:luo 回复日期:2003-11-27 16:57:51
<br>内容:只要把这句vector<string,alloctor> file_names改为<BR>vector<string> file_names就应该可以了。
<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 + -