What are the data types of the variables?
With the mdy variables as ints and the c as a char, it seems to work for me - I get the negative values.
A full code sample illustrating your problem will help us help you.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
That should work. Please post the exact data file contents you're trying to read.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
And, the test you're doing is only testing the filename the user entered, it does not test if there's actually a file or if it has any content.
(this should have come after my next reply - they got out of order somehow)
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
You're asking a question that's not exactly what I think you mean.
if ( (! ifile.size( ) ) == 0 ) means, logically negate the value the size function returns, giving you a boolean true or false value, then compare that to zero, which is considered false.
If you're trying to find out if the user actually entered some string as the file name, try
if( ifile.size( ) == 0 )
{
//error handler
}
else
{
fin.open( ifile.c_str( ) );
}
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
every text should cover this
fin.open ( "somefile.txt" );
if( !fin ) // or if( fin.fail( ) )
{
//error handler goes here
}
else
{
//file opened successfully, start reading
}
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
while ( getline ( fin, str ) )
{
//do any other processing
}
If the read action is successful, you enter the loop body. If the read action fails, loop ends.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228