Microsoft KB Archive/92733

{|
 * width="100%"|

Using an IFSTREAM Object with the &quot;>>&quot; Operator

 * }

Q92733

-

The information in this article applies to:


 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5

-

An IFSTREAM object may be used as input for the &quot;>>&quot; 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 // //****************************************************


 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 

ifstream myfileinput;              // IFSTREAM Object For >> Operator

void main {  int     number; char   *instring;

myfileinput.open(&quot;my.dat&quot;, ios::in, filebuf::sh_read);

myfileinput >> number;     //** Insert into number

if (number == 180) cout << &quot;worked for integers&quot; << endl; else cout << &quot;failed for integers&quot; << endl; instring = (char*)calloc(25, sizeof(char));

myfileinput >> instring;  //** Insert into char*

if (0 == strcmp(instring,&quot;string&quot;)) cout << &quot;worked for strings&quot; << endl; else cout << &quot;failed for strings&quot; << endl; }

MY.DAT File


180 string

Output
worked for integers worked for strings Additional query words: kbinf 7.00 1.00 1.50

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbZNotKeyword3 kbCVC700DOS