ifstream in("test.txt");
方法1
string str( (istreambuf_iterator<char>(in)), (istreambuf_iterator<char>()) );
方法2
string str;
copy( istreambuf_iterator<char>(in), istreambuf_iterator<char>(), back_inserter(str) ); 那位大大能解释下上述调用的原理,看的好晕额,越详细越好。分全送上
方法1
string str( (istreambuf_iterator<char>(in)), (istreambuf_iterator<char>()) );
方法2
string str;
copy( istreambuf_iterator<char>(in), istreambuf_iterator<char>(), back_inserter(str) ); 那位大大能解释下上述调用的原理,看的好晕额,越详细越好。分全送上
istreambuf_iterator <char>() 这个是end iteratorcopy(起始it,结束it,...str)
就是把it抄到str里面...........
while(cin>>c)
template<class InIter>basic_string(InIter start, InIter end, const Allocator &a = Allocator())就是形式构造一个字符串,该串包含start和end指定的范围内的元素