Using an IFSTREAM Object with the ">>" OperatorLast reviewed: July 17, 1997Article ID: Q92733 |
1.00 1.50
WINDOWS
kbprg
The information in this article applies to:
An IFSTREAM object may be used as input for the ">>" insertion operator. Doing so provides a method to retrieve data from an IFSTREAM other than CIN. The sample code below demonstrates this task.
Sample Code
/* * Compile options needed: cl /D_DOS test.cpp safxcrd.lib */ //**************************************************** // // Demo using an IFSTREAM Object For >> operator // //**************************************************** #include <fstream.h> #include <iostream.h> #include <malloc.h> #include <string.h> ifstream myfileinput; // IFSTREAM Object For >> Operator void main(){ int number; char *instring; myfileinput.open("my.dat", ios::in, filebuf::sh_read); myfileinput >> number; //** Insert into number if (number == 180) cout << "worked for integers" << endl; else cout << "failed for integers" << endl; instring = (char*)calloc(25, sizeof(char)); myfileinput >> instring; //** Insert into char* if (0 == strcmp(instring,"string")) cout << "worked for strings" << endl; else cout << "failed for strings" << endl;}
MY.DAT File180 string
Outputworked for integers worked for strings
|
Additional reference words: kbinf 7.00 1.00 1.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |