I'm reading a file in C++ using streams, specifically, fstream, not ifstream.
blah blah blah\n
blah blah\n
blah blah blah blah \n
end
This repeats over and over with
- varble number of blah's in each line,
- constant number of lines between each end, end is the delimiter here
I want to read one set of data, then store it in a character array, in a C style structure. I started by trying to use getline() but the delimter can only be one character, not three. I obviously can't try to read a set number of bytes using just read(), as the number will be different for each set.
So I'm torn over what the easiest (and most robust) thing to do here is. Should I call getline until I find an 'end' string, while appending each string over and over?
I tried a 2D char array but I copying to it was kind of a pain. Can I use strncpy here? I don't think this worked
char buf[10][10];
strncpy(buf[1], "blah blah",10);
I have a few ideas here, but I'm just not sure which one (or the one I haven't though of) is the best.
EDIT: So this is for a networking application, so the size of the char array (or string) should always be the same. Also, there should be no pointers in the structure.
Related question: is the way that a char array and a std::string are stored in memory the same? I always though there was some overhead with std::string.