[英]Iterators without STL containers
At first sorry about my English.起初对我的英语感到抱歉。 I
m preparing for my exam and I need to practice iterators, that don
t work with containers.我
m preparing for my exam and I need to practice iterators, that don
用于容器。 I would like to input some symbols right to the symbol like '\n' and I have no clue how can I do that.我想在 '\n' 之类的符号旁边输入一些符号,但我不知道该怎么做。 The problem is I am not able to stop entering symbols.
问题是我无法停止输入符号。 Hope you can help me.
希望您能够帮助我。 Sincerely thank you!
衷心感谢您!
#include <iostream>
#include <iterator>
#include <algorithm>
#include <fstream>
using namespace std;
int main()
{
ofstream out("name.txt");
istream_iterator<char> it(cin);
istream_iterator<char> end_of_stream;
ostream_iterator<char> fout(out, " ");
copy (it, end_of_stream, fout);
}
There's no algorithm to copy until you get a particular value (I think) so instead you have to write your own loop.在获得特定值(我认为)之前,没有要复制的算法,因此您必须编写自己的循环。
Like this像这样
while (it != end_of_stream && *it != '\n')
{
fout << *it;
++it;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.