■ P33, L4
Reader letter:
I bought Mr. Essential C and C Primer published, with a section code like this.
(Page C Primer 1102, and Essential C 1.7)
#include
Using namespace std;
void main ()
{
...
FSTREAM IO ("Word.txt", iOS_Base :: in | iOS_BASE :: App);
...
}
There is no problem with the compilation and link, but it is performed by iOS_BASE :: in and iOS_BASE :: App.
IO (FSTREAM object) can't open Word.txt and read and write it, I use it
VC6. Is this the problem of VC or a Quality of the C itself?
I found out
Change this trip to the following
FSTREAM IO ("Word.txt", iOS_Base :: in | iOS_BASE :: App | iOS_BASE :: Out);
Open Word.txt normally
Please help answer, thank you. This error is that students discovered when I was in class, and I will then test the results.
Houjie replied:
I wrote a small-range test and add an annotation, as follows.
#include
#include
Using namespace std;
int main ()
{
// Note: IOS_BASE :: in | iOS_BASE :: App on the book
FSTREAM IO ("Word.out", iOS_BASE :: in | iOS_BASE :: App | iOS_BASE :: OUT);
IF (! io) {
COUT << "can not open";
EXIT (-1);
}
INT I;
IO >> I;
COUT << i << endl;
IO << 23;
IO << 28;
// Write is written, how to read it in the future? Therefore, it is also necessary to consider the overall format. Not much here.
}
/ *
Note that when observing the contents of the file, it is inaccurate with Type Word.out.
Binary Dumper, such as TDUMP.EXE, should be used.
In VC6, files cannot be opened correctly unless iOS_BASE :: OUT.
But even if you add iOS_BASE :: OUT, you can't smoothly append.
In CB5, you can smoothly open the file and read the information, but it is not possible to properly and correct Append.
Must add iOS_BASE :: OUT to successfully.
Unable to compile in G291.
* /
Thank: TSE-CHEN YEH
Date: 2002/12/13