cout<<矢量<串GT; [英] cout << vector<string>
问题描述
在boost :: program_options教程中,作者包括以下
代码:
cout<< 输入文件是:
<< VM ["输入文件"]。为< vector< string()
<< " \ n";
基本上,他试图在一行中打印一个字符串向量。我可以
没有得到这个编译(更不用说运行了)。为了让它编译和运行,我将
重新编写为:
vector< stringv = vm [" input-file"]。as< vector< string();
vector< string> :: const_iterator i;
for(i = v.begin(); < br $>
i!= v.end();
++ i)
{
cout<< * citer<< " ;
}
有谁知道原始代码行是否正确?如果是这样的话,我错过了什么?b $ b缺少什么?
In the boost::program_options tutorial, the author included the following
code:
cout << "Input files are: "
<< vm["input-file"].as< vector<string()
<< "\n";
Basically, he is trying to print a vector of string, in one line. I could
not get this compile (let alone run). To get it to compile and run, I had
to re-write it as:
vector<stringv = vm["input-file"].as< vector<string();
vector<string>::const_iterator i;
for ( i = v.begin();
i != v.end();
++i )
{
cout << *citer << " ";
}
Does anyone know if the original line of code is correct? If so, what was I
missing?
推荐答案
11月6日,11:06 * pm ,barcaroller, < barcarol ... @ music.netwrote:
On Nov 6, 11:06*pm, "barcaroller" <barcarol...@music.netwrote:
在boost :: program_options教程中,作者包括以下
代码:
* * cout<< 输入文件是:"
* * * * *<< VM ["输入文件"]。为< vector< string()
* * * * *<< " \ n";
基本上,他试图在一行中打印一个字符串向量。 *我可以
没有得到这个编译(更不用说运行了)。 *为了让它编译和运行,我将
重新编写为:
* * vector< stringv = vm [" input-文件"]为< vector< string();
* * vector< string> :: const_iterator i;
* * for(* i * = v .begin();
* * * * * * i!= v.end();
* * * * * ++ i)
* * {
* * * * cout<< * citer<< " ;
* *}
有谁知道原始代码行是否正确? *如果是这样,我缺少什么?
?
In the boost::program_options tutorial, the author included the following
code:
* * cout << "Input files are: "
* * * * *<< vm["input-file"].as< vector<string()
* * * * *<< "\n";
Basically, he is trying to print a vector of string, in one line. *I could
not get this compile (let alone run). *To get it to compile and run, I had
to re-write it as:
* * vector<stringv = vm["input-file"].as< vector<string();
* * vector<string>::const_iterator i;
* * for ( * i *= v.begin();
* * * * * * i != v.end();
* * * * * ++i )
* * {
* * * * cout << *citer << " ";
* * }
Does anyone know if the original line of code is correct? *If so, what was I
missing?
该示例可能假设存在重载运算符<<()for
std :: ostream和std :: vector<> ;,类似这样的事情:
#include< ostream>
#include< iterator>
#include<算法>
命名空间std {
模板< class A1,A2类>
ostream& operator<(ostream& s,vector< A1,A2const& vec)
{
copy(vec.begin(),vec.end(),ostream_iterator< A1>(s,
));
返回s;
}
}
-
Max
The example probably assumes there is an overloaded operator<<() for
std::ostream and std::vector<>, something like this:
#include <ostream>
#include <iterator>
#include <algorithm>
namespace std {
template<class A1, class A2>
ostream& operator<<(ostream& s, vector<A1, A2const& vec)
{
copy(vec.begin(), vec.end(), ostream_iterator<A1>(s, "
"));
return s;
}
}
--
Max
On 2008-11-06 18:06 :47-0500,barcaroller < ba ********* @ music.netsaid:
On 2008-11-06 18:06:47 -0500, "barcaroller" <ba*********@music.netsaid:
>
在boost :: program_options教程中,作者包括以下
代码:
cout<< 输入文件是:
<< VM ["输入文件"]。为< vector< string()
<< " \ n";
有谁知道原始代码行是否正确?
>
In the boost::program_options tutorial, the author included the following
code:
cout << "Input files are: "
<< vm["input-file"].as< vector<string()
<< "\n";
Does anyone know if the original line of code is correct?
不在标准C ++中。
Not in standard C++.
如果是这样,我是什么
失踪了?
If so, what was I
missing?
教程中某处提到的一些代码,或者更好的教程。
-
Pete
Roundhouse Consulting,Ltd。( www.versatilecoding.com )
标准C ++库扩展:一个教程和参考资料的作者
( www.petebecker.com/tr1book )
Either some code that was mentioned somewhere in the tutorial, or a
better tutorial.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
On 2008-11-07 06:03:15 -0500,Maxim Yegorushkin
< ma *************** @ gmail.comsaid:
On 2008-11-07 06:03:15 -0500, Maxim Yegorushkin
<ma***************@gmail.comsaid:
>
该示例可能假设存在重载运算符<<()for
std :: ostream和std :: vector<>,类似这样:
#include< ostream>
#include< iterator>
#include< algorithm>
namespace std {
模板< class A1,A2类>
ostream& operator<(ostream& s,vector< A1,A2const& vec)
{
copy(vec.begin(),vec.end(),ostream_iterator< A1>(s,
));
返回s;
}
}
>
The example probably assumes there is an overloaded operator<<() for
std::ostream and std::vector<>, something like this:
#include <ostream>
#include <iterator>
#include <algorithm>
namespace std {
template<class A1, class A2>
ostream& operator<<(ostream& s, vector<A1, A2const& vec)
{
copy(vec.begin(), vec.end(), ostream_iterator<A1>(s, "
"));
return s;
}
}
哪些是未定义的行为。当它们依赖于用户定义的类型时,你只能将模板特化添加到命名空间std。
-
Pete
Roundhouse Consulting,Ltd。( www.versatilecoding.com )作者
标准C ++库扩展:教程和参考
( www.petebecker.com/tr1book )
Which has undefined behavior. You can only add template specializations
to namespace std when they depend on user-defined types.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
这篇关于cout<<矢量<串GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!