fstream inconsistent with stdio

The following code works quite well for me (it talks to the modem device):

#include <cstdlib>
#include <fstream>
#include <string>
#include <iostream>
#include <cstring>

static char const sc_device_name] = “/dev/modem”;
static char const sc_cmd ] = "AT
", sc_exp ] = "OK
";

extern “C” int main (int argc, char const *const arg])
{
register FILE (*const a_m) ((std:: fopen (sc_device_name, “r+”)));
if (a_m)
{ register int a_code;
if (std:: fputs (sc_cmd, a_m) == EOF)
{ std:: perror (“write”); a_code = +EXIT_FAILURE; }
else for ( ; ; ) {
register char a_buf +BUFSIZ];
register char *a_res = std:: fgets (a_buf, +BUFSIZ, a_m);
if (a_res) {
if (fputs (a_res, stdout) == EOF)
{ std:: perror (“write”); a_code = +EXIT_FAILURE; }
else a_code = +EXIT_SUCCESS; if (!std:: strcmp (a_res, sc_exp)) break; }
else { std:: perror (“read”); a_code = +EXIT_FAILURE; break; }}
if (std:: fclose (a_m)) { std:: perror (“close”); return +EXIT_FAILURE; }
else return +a_code; }
else { std:: perror (“open”); return +EXIT_FAILURE; }}

However, if I replace the FILE * with std::fstream, mutatis mutandis, I am unable to read: a_m. rdbuf() -> sbumpc () returns EOF.

Why is that?

fstream and stdio are different buffered I/O libraries. Stick to one or the other and don’t mix.

I do not mix fstream and stdio. I prefer to use fstream, of course, but the problem is that fstream (mysteriously) does not work.
A possible culprit is this change: [gcc] Revision 68420](http://gcc.gnu.org/viewcvs?view=revision&revision=68420)