Manipulating C strings
I am new to C++. My programming experience thus far has been in Java. I've been given an assignment to parse some things out of a file using C++ file streams but I am not allowed to use the C++ strings to manipulate what comes from the file. I have to use cstrings instead. I am trying to read the file one line at a time but the specifications say that I have to be able delimit on /r, /n, and /r/n. I can't figure out a safe way to do that with cstring. Every way that I come up with either is unsafe because of potential buffer overflows or makes it so that I potential lose data that I already got from the file. Can anyone propose a good way to approach this problem? Thanks!
By "cstrings" do you mean standard C strings, using char arrays?
To delimit on either of '\r', '\n' or '\r' & '\n', you'd have to use a lookahead if you see a '\r' character, since the only way to know if the NEXT character is '\n' is to read that character.
One way to achieve that would be to have your own little wrapper struct for a stream, and have two more fields, one with the lookahead character, the other with the "lookahead is valid" boolean value.
get should be able to munge \r\n, or any subset thereof into \n, as in
file.get(buffer, sizeof buffer, '\n');