Is it possible to read dos files in linux using an ifstream
When I use the std::ifstream to open a file that has been written in dos format, the ifstream does not seem to be able to open the file correctly since when I call good() on the stream afterwards it fails (returns false). I tried opening the file in binary mode as well as the default "in" mode and neither worked. If I convert the file to unix using dos2unix, everything works fine.
The goal behind being able to do this is that I want to be able to read a file and parse it, but I cannot guarantee that the file has not been saved in dos (Windows) or unix (Linux) format. 开发者_运维问答Ideally, I would like to be able to use the ifstream.
Any suggestions?
Thanks!
The file format will NOT affect your ability to open it.
It is more likely that your path is not correct.
It seems extremely unlikely that GCC would do such a thing.
I suggest doing my_ifstream.exceptions( ios::failbit | ios::badbit );
before opening it, and running in the debugger. Then you can see where it ceased to be good.
Also, opening the file in binary mode (ios::in | ios::binary)
should eliminate any possibility of the implementation being choosy over the contents of the file.
精彩评论