A
Aleks Dubinskiy
Hi folks,
I am well aware of the superiority of using streams and operators << / >>
instead of the old-style printf and scanf. However, there is only one
obstacle that prevents me from switching to the better form.
scanf has the following really convenient syntax:
fscanf(pFile, "prfl num: %d\n", &nPrflNum);
The convenient part about it is that it's almost an exact copy of the
fprintf operation that created the input. In particular it allows to skip
over a particular text by just writing what it is.
It seems to be very difficult to replace this with a convenient input stream
version, such as:
input>>"prfl num: ">>nPrflNum;
This code turns out to be illegal, because the input stream class doesn't
know how to input constant strings. The workaround I know for this is quite
cumbersome, involving reading characters one by one, and verifying if they
fit the pattern "prfl num: ", or ignoring everything until a numeric
character is found in the stream.
Is there a more straightforward / painless way to do what I want?
Cheers,
Aleks D.
I am well aware of the superiority of using streams and operators << / >>
instead of the old-style printf and scanf. However, there is only one
obstacle that prevents me from switching to the better form.
scanf has the following really convenient syntax:
fscanf(pFile, "prfl num: %d\n", &nPrflNum);
The convenient part about it is that it's almost an exact copy of the
fprintf operation that created the input. In particular it allows to skip
over a particular text by just writing what it is.
It seems to be very difficult to replace this with a convenient input stream
version, such as:
input>>"prfl num: ">>nPrflNum;
This code turns out to be illegal, because the input stream class doesn't
know how to input constant strings. The workaround I know for this is quite
cumbersome, involving reading characters one by one, and verifying if they
fit the pattern "prfl num: ", or ignoring everything until a numeric
character is found in the stream.
Is there a more straightforward / painless way to do what I want?
Cheers,
Aleks D.