gpt4 book ai didi

c++ - 在控制台中输入什么来触发流结束?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:50:23 28 4
gpt4 key购买 nike

以下代码来自本书:The C++ Standard Library Second Edition。

如何在 Mac Yosemite 上运行它?

在控制台中,我输入了 a、enter、b、enter...no ends....如何输入流结束?

/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference, 2nd Edition"
* by Nicolai M. Josuttis, Addison-Wesley, 2012
*
* (C) Copyright Nicolai M. Josuttis 2012.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <iterator>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
vector<string> coll;

// read all words from the standard input
// - source: all strings until end-of-file (or error)
// - destination: coll (inserting)
copy (istream_iterator<string>(cin), // start of source
istream_iterator<string>(), // end of source
back_inserter(coll)); // destination

// sort elements
sort (coll.begin(), coll.end());

// print all elements without duplicates
// - source: coll
// - destination: standard output (with newline between elements)
unique_copy (coll.cbegin(), coll.cend(), // source
ostream_iterator<string>(cout,"\n")); // destination
}

最佳答案

Mac OS 和其他 UNIX 衍生产品上的 Ctrl-D。

关于c++ - 在控制台中输入什么来触发流结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30123143/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com