Click here to Skip to main content
15,902,447 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++ newbie here, some help is needed. Pin
C_Zealot23-May-07 3:16
C_Zealot23-May-07 3:16 
AnswerRe: C++ newbie here, some help is needed. Pin
Arman S.23-May-07 3:39
Arman S.23-May-07 3:39 
GeneralRe: C++ newbie here, some help is needed. Pin
C_Zealot23-May-07 12:47
C_Zealot23-May-07 12:47 
AnswerRe: C++ newbie here, some help is needed. Pin
James R. Twine23-May-07 3:43
James R. Twine23-May-07 3:43 
GeneralRe: C++ newbie here, some help is needed. Pin
C_Zealot23-May-07 12:47
C_Zealot23-May-07 12:47 
AnswerRe: C++ newbie here, some help is needed. Pin
David Crow23-May-07 3:44
David Crow23-May-07 3:44 
GeneralRe: C++ newbie here, some help is needed. Pin
C_Zealot23-May-07 12:47
C_Zealot23-May-07 12:47 
AnswerRe: C++ newbie here, some help is needed. [modified] Pin
Michael Sadlon23-May-07 8:33
Michael Sadlon23-May-07 8:33 
C_Zealot wrote:
I am stuck right here. Am I supposed to check the return value of ifstream? Or am I supposed to employ a member function of ifstream, but which one?


You need to check if ifstream in is a valid stream. It's an object so you need to call it's is_open(), good(), or bad() function.

if(!in.is_open())
     cerr << "File didn't open correctly!";

if(in.bad())
     cerr << "File bad bit is set!";

if(!in.good())
     cerr << "File is not good for use!";


You can also just do:
if(!in)
     cerr << "File didn't open correctly!";

Which I believe checks if the file opened, but does NOT check if the any of the bad bits are set (could be wrong).

I recommend the in.good() approach, personally, as it checks everything for you.

My favorite pure C++ reference site. Goes great alongside MSDN.

http://www.cplusplus.com/reference/iostream/ifstream/[^]

Good luck Smile | :)


-- modified at 14:41 Wednesday 23rd May, 2007
GeneralRe: C++ newbie here, some help is needed. Pin
C_Zealot23-May-07 12:46
C_Zealot23-May-07 12:46 
Questionloop help Pin
klutez12323-May-07 3:06
klutez12323-May-07 3:06 
AnswerRe: loop help Pin
David Crow23-May-07 3:54
David Crow23-May-07 3:54 
QuestionCREATESTRUCT& cs problem Pin
prithaa23-May-07 1:48
prithaa23-May-07 1:48 
AnswerRe: CREATESTRUCT& cs problem Pin
Arman S.23-May-07 3:48
Arman S.23-May-07 3:48 
AnswerRe: CREATESTRUCT&amp; cs problem Pin
Mark Salsbery23-May-07 5:45
Mark Salsbery23-May-07 5:45 
GeneralRe: CREATESTRUCT&amp; cs problem Pin
prithaa23-May-07 18:15
prithaa23-May-07 18:15 
GeneralRe: CREATESTRUCT&amp; cs problem Pin
Mark Salsbery24-May-07 4:51
Mark Salsbery24-May-07 4:51 
QuestionMy class wizard is empty Pin
garfield18523-May-07 1:36
garfield18523-May-07 1:36 
AnswerRe: My class wizard is empty Pin
Cedric Moonen23-May-07 1:42
Cedric Moonen23-May-07 1:42 
GeneralRe: My class wizard is empty Pin
garfield18523-May-07 1:47
garfield18523-May-07 1:47 
Questionissues with Vista / VS 2005? Pin
ldsdbomber23-May-07 1:14
ldsdbomber23-May-07 1:14 
AnswerRe: issues with Vista / VS 2005? Pin
JudyL_MD23-May-07 2:24
JudyL_MD23-May-07 2:24 
GeneralRe: issues with Vista / VS 2005? Pin
ldsdbomber30-May-07 17:05
ldsdbomber30-May-07 17:05 
GeneralRe: issues with Vista / VS 2005? Pin
ldsdbomber30-May-07 23:58
ldsdbomber30-May-07 23:58 
QuestionLinker : ERROR.....??? Pin
Thoyib Bustomi23-May-07 1:06
Thoyib Bustomi23-May-07 1:06 
AnswerRe: Linker : ERROR.....??? Pin
Rage23-May-07 1:23
professionalRage23-May-07 1:23 

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.