If you use only the cin object, you don’t need to construct an input stream. You must construct an input stream if you use:
There are three ways to create an input file stream:
ifstream myFile; // On the stack
myFile.open( "filename", iosmode );
ifstream* pmyFile = new ifstream; // On the heap
pmyFile->open( "filename", iosmode );
ifstream myFile( "filename", iosmode );
int fd = _open( "filename", dosmode );
ifstream myFile1( fd ); // Buffered mode (default)
ifstream myFile2( fd, NULL, 0 ); // Unbuffered mode
ifstream myFile3( fd, pch, buflen ); // User-supplied buffer
Input string stream constructors require the address of preallocated, preinitialized storage:
char s[] = "123.45";
double amt;
istrstream myString( s );
myString >> amt; // Amt should contain 123.45