Loading a file into a vector

前端 未结 5 494
后悔当初
后悔当初 2020-12-03 03:20

I would like to load the contents of a text file into a vector (or into any char input iterator, if that is possible). Currently my code looks like

5条回答
  •  醉酒成梦
    2020-12-03 03:43

    use an iterator:

    #include 
    
    istream_iterator data( file );
    istream_iterator end;
    vec.insert( std::back_inserter(vec), data, end );
    

提交回复
热议问题