ostream迭代器在c ++中的使用 [英] ostream iterator usage in c++
本文介绍了ostream迭代器在c ++中的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是代码
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iterator>
using std::vector;
using std::string;
using std::cout;
using std::cin;
using std::ostream_iterator;
using std::cout;
int main(){
vector <string> me;
string s;
while ((cin>>s) && s!="end")
me.push_back(s);
std::copy(me.begin(),me.end(),
std::ostream_iterator(cout,"\n"));
return 0;
}
但这里是错误
1>------ Build started: Project: stl_implementation, Configuration: Debug Win32 ------
1> implementation.cpp
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): error C2955: 'std::ostream_iterator' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\iterator(516) : see declaration of 'std::ostream_iterator'
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): error C2955: 'std::ostream_iterator' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\iterator(516) : see declaration of 'std::ostream_iterator'
1>c:\users\david\documents\visual studio 2010\projects\stl_implementation\implementation.cpp(21): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
推荐答案
ostream_iterator
需要一个模板参数;在这种情况下使用 ostream_iterator< string>
。
ostream_iterator
needs a template argument; use ostream_iterator<string>
in this case.
这篇关于ostream迭代器在c ++中的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文