Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Exit method safely

$
0
0
hi
I have wrote this method to read files the question is about this code here

if( fileName.fail() )
{
        cerr << "Cannot open file: " << endl;
	system( "PAUSE" );
	return( 1 );
}



I know my method doesn't return any think because it is void so how would I exit this method safely if the file cannot be found?
Any help would be appreciated

void ReadFile::getInfo()
{
	string info;
	fileName.open( "Test.txt" );

	if( fileName.fail() )
	{
		cerr << "Cannot open file: " << endl;
		system( "PAUSE" );
		return( 1 );
	}

	fileName >> info;
	cout << info << endl;
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles