Click here to Skip to main content
15,922,533 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionstl:fstream exeption-handling and file-closing [modified] Pin
Tomerland6-May-08 0:46
Tomerland6-May-08 0:46 
Dear developers,

I have the following code:


try {
    ifstream file;
    file.open("file.txt");
	
	file >> ... ;	
    file.close();	
}
catch(......) {
  ...
  ---> do I have to close the file here? <----
}


My question:
Do I have to close the file in the catch-handler? Or is it automatically closed when the destructor of file runs.


Kind regards


PS:
Another question: How can I insert code here with indentation?

modified on Tuesday, May 6, 2008 7:06 AM

AnswerRe: stl:fstream exeption-handling and file-closing Pin
Rajesh R Subramanian6-May-08 0:58
professionalRajesh R Subramanian6-May-08 0:58 
QuestionRe: stl:fstream exeption-handling and file-closing Pin
CPallini6-May-08 1:01
mveCPallini6-May-08 1:01 
AnswerRe: stl:fstream exeption-handling and file-closing Pin
toxcct6-May-08 1:40
toxcct6-May-08 1:40 
AnswerRe: stl:fstream exeption-handling and file-closing Pin
Tomerland6-May-08 1:45
Tomerland6-May-08 1:45 
Questionhelp me please Pin
sofia_1116-May-08 0:39
sofia_1116-May-08 0:39 
AnswerRe: help me please Pin
Rajkumar R6-May-08 0:52
Rajkumar R6-May-08 0:52 
GeneralRe: help me please Pin
sofia_1116-May-08 5:31
sofia_1116-May-08 5:31 
QuestionRe: help me please Pin
Rajesh R Subramanian6-May-08 0:55
professionalRajesh R Subramanian6-May-08 0:55 
AnswerRe: help me please Pin
sofia_1116-May-08 5:35
sofia_1116-May-08 5:35 
QuestionRe: help me please Pin
CPallini6-May-08 0:57
mveCPallini6-May-08 0:57 
JokeRe: help me please Pin
Rajesh R Subramanian6-May-08 1:00
professionalRajesh R Subramanian6-May-08 1:00 
JokeRe: help me please Pin
CPallini6-May-08 1:04
mveCPallini6-May-08 1:04 
AnswerRe: help me please Pin
sofia_1116-May-08 5:37
sofia_1116-May-08 5:37 
QuestionHelp! How to convert an array to bitmap? Pin
npkinh6-May-08 0:30
npkinh6-May-08 0:30 
AnswerRe: Help! How to convert an array to bitmap? Pin
ThatsAlok6-May-08 0:35
ThatsAlok6-May-08 0:35 
GeneralRe: Help! How to convert an array to bitmap? Pin
npkinh6-May-08 1:00
npkinh6-May-08 1:00 
GeneralRe: Help! How to convert an array to bitmap? Pin
Nelek6-May-08 2:02
protectorNelek6-May-08 2:02 
AnswerRe: Help! How to convert an array to bitmap? Pin
Mark Salsbery6-May-08 5:11
Mark Salsbery6-May-08 5:11 
QuestionHow to Convert Local time to UTC Time in WM5.0 [modified] Pin
Mohanraj D6-May-08 0:14
Mohanraj D6-May-08 0:14 
AnswerRe: How to Convert Local time to UTC Time in WM5.0 Pin
perle16-May-08 1:22
perle16-May-08 1:22 
GeneralRe: How to Convert Local time to UTC Time in WM5.0 Pin
Mohanraj D6-May-08 1:36
Mohanraj D6-May-08 1:36 
AnswerRe: How to Convert Local time to UTC Time in WM5.0 [modified] Pin
Rajkumar R6-May-08 1:55
Rajkumar R6-May-08 1:55 
AnswerRe: How to Convert Local time to UTC Time in WM5.0 Pin
Rajesh R Subramanian6-May-08 2:03
professionalRajesh R Subramanian6-May-08 2:03 
GeneralRe: How to Convert Local time to UTC Time in WM5.0 Pin
Rajkumar R6-May-08 2:10
Rajkumar R6-May-08 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.