Using an IFSTREAM Object with the ">>" OperatorID: Q92733
|
/*
* 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;
}
180
string
worked for integers
worked for strings
Additional query words: kbinf 7.00 1.00 1.50
Keywords : kb16bitonly
Version :
Platform :
Issue type :
Last Reviewed: July 27, 1999