I have read the latest post about istream_iterator here and this leads to another question.
I have a file which contains char sequences ("strings"), separated by \0.
I'd like to be able to read the file using istream_iterators. I have been able to accomplish this when the delimiter in the file is \n rather than \0.
Could someone please help me out?
Code:// using istringstream instead of ifstream for this sample code std::istringstream iss( // "text10\0text20\0text30\0text40\0text50\0text60\0" // this does not work "text10\ntext20\ntext30\ntext40\ntext50\ntext60\n" // this works ); int main() { std::istream_iterator<std::string> it_first(iss); std::istream_iterator<std::string> it_last; std::ostream_iterator<std::string> it_out(std::cout, " "); std::copy(it_first, it_last, it_out); std::cout << std::endl; }




Reply With Quote