can you use Insert Iterators while reading from a file to put the data into STL container?
for example:
FILE *stream;
fread(back_inserter(std::list), sizeof(int), 1, stream);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C++ streams are not compatible with C stdio streams. In other words, you can’t use C++ iterators with
FILE*orfread. However, if you use the C++std::fstreamfacilities along withistream_iterator, you can use an insertion iterator to insert into a C++ container.Assuming you have an input file “input.txt” which contains ASCII text numbers separated by whitespace, you can do: