几番离愁 发表于 2019-6-9 19:45:11

c++求助

#include <iostream>
#include <set>
#include <string>

int main()
{
        using namespace std;
        const int N = 6;
        string s1 = { "buffoon", "thinkers", "for", "heavy", "can", "for" };
        set<string> A(s1, s1 + N);
        ostream_iterator<string, char> out(cout, " ");
        copy(A.begin(), A.end(), out);//buffoon can for heavy thinkers
        return 0;
}

ostream_iterator<string, char> out(cout, " ");//这句话的string,char分别有什么用吗,我把char去掉好像也可以打印

TOP_LK 发表于 2019-6-9 21:11:51


因为你要输出的是string,所以要写string;
template <class Type, class CharType = char, class Traits = char_traits <CharType>>
class ostream_iterator;
因为默认就是char,所以去掉也行。
页: [1]
查看完整版本: c++求助