Click here to Skip to main content
15,899,475 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalmaybe someone can help me out. Pin
donttrip24-Dec-04 16:56
donttrip24-Dec-04 16:56 
GeneralRe: maybe someone can help me out. Pin
Rassul Yunussov24-Dec-04 17:51
Rassul Yunussov24-Dec-04 17:51 
GeneralRe: maybe someone can help me out. Pin
Dennis Gourjii24-Dec-04 23:47
Dennis Gourjii24-Dec-04 23:47 
GeneralRe: maybe someone can help me out. Pin
Michael Dunn25-Dec-04 5:55
sitebuilderMichael Dunn25-Dec-04 5:55 
GeneralData Buffer into a VB .Net Byte Array Pin
Daniel Gow24-Dec-04 16:01
Daniel Gow24-Dec-04 16:01 
GeneralSeparate compilation Problem Pin
elixxo2924-Dec-04 15:00
elixxo2924-Dec-04 15:00 
GeneralIE Add-on for text translation Pin
Samsung24-Dec-04 14:11
Samsung24-Dec-04 14:11 
GeneralIfstream returning crashfest. Hlplz :) Pin
Anonymous24-Dec-04 8:55
Anonymous24-Dec-04 8:55 
I'm just goofing off and I'm having an issue with my ifstream variable ifile when I attempt to close it. I sorta understand why it's not working but I don't know how to maintain my elegance and still accomplish my purpose. Here is a simplified portion of the code I have now:

<br />
//8888888888888888888//<br />
<br />
string GetFilename(char []);<br />
ifstream& OpenFile(string);<br />
<br />
//8888888888888888888//<br />
<br />
void main()<br />
{<br />
  string input;<br />
  ifstream ifile;<br />
  <br />
  input=GetFilename("manipulate:");<br />
  ifile=OpenFile(input);<br />
  if (ifile.fail()){<br />
    cout<<"File does not exist!";}<br />
  else{<br />
    ifile.close();}<br />
}<br />
<br />
//8888888888888888888//<br />
<br />
string GetFilename(char special[12])<br />
{<br />
  static string input;<br />
<br />
  cout<<"Please enter the name of the file you wish to "<<special<<endl;<br />
  cin>>input;<br />
  return input;<br />
}<br />
<br />
//8888888888888888888//<br />
<br />
ifstream& OpenFile(string input)<br />
{<br />
  static char filename[80];<br />
  strcpy(filename, input.c_str());<br />
<br />
  static ifstream ifile;<br />
  ifile.open(filename);<br />
  return ifile;<br />
}<br />
<br />
//8888888888888888888//<br />


This program crashes when I try to close a file I opened that actually exists. I figure it has something to do with, am I closing the ifile is OpenFile or the one in main? A quick solution would be to create a global ifstream variable but how exactly does one effectively return an ifstream variable? The static declaration in OpenFile probably is causing havok too. Any help would be greatly appreciated.

P.S. I'll still be thinking on this for a while...
GeneralRe: Ifstream returning crashfest. Hlplz :) Pin
Neville Franks24-Dec-04 9:53
Neville Franks24-Dec-04 9:53 
GeneralRe: Ifstream returning crashfest. Hlplz :) Pin
Anonymous24-Dec-04 13:46
Anonymous24-Dec-04 13:46 
GeneralRe: Ifstream returning crashfest. Hlplz :) Pin
Anonymous24-Dec-04 13:53
Anonymous24-Dec-04 13:53 
GeneralRe: Ifstream returning crashfest. Hlplz :) Pin
Neville Franks24-Dec-04 14:08
Neville Franks24-Dec-04 14:08 
QuestionSDI Project-How do I Implement Resizing of Modeless Dialog Windows? Pin
jerry1211a24-Dec-04 7:36
jerry1211a24-Dec-04 7:36 
AnswerRe: SDI Project-How do I Implement Resizing of Modeless Dialog Windows? Pin
Dennis Gourjii24-Dec-04 23:51
Dennis Gourjii24-Dec-04 23:51 
GeneralRe: SDI Project-How do I Implement Resizing of Modeless Dialog Windows? Pin
jerry1211a25-Dec-04 4:11
jerry1211a25-Dec-04 4:11 
AnswerRe: SDI Project-How do I Implement Resizing of Modeless Dialog Windows? Pin
John R. Shaw25-Dec-04 6:01
John R. Shaw25-Dec-04 6:01 
GeneralDetecting events on Folder Pin
Imtiaz Murtaza24-Dec-04 5:13
Imtiaz Murtaza24-Dec-04 5:13 
GeneralRe: Detecting events on Folder Pin
Michael Dunn24-Dec-04 5:38
sitebuilderMichael Dunn24-Dec-04 5:38 
GeneralRe: Detecting events on Folder Pin
Dennis Gourjii24-Dec-04 23:56
Dennis Gourjii24-Dec-04 23:56 
GeneralRe: Detecting events on Folder Pin
Michael Dunn25-Dec-04 5:32
sitebuilderMichael Dunn25-Dec-04 5:32 
GeneralIcon Question Pin
mango_lier24-Dec-04 3:54
mango_lier24-Dec-04 3:54 
GeneralRe: Icon Question Pin
Dennis Gourjii24-Dec-04 23:59
Dennis Gourjii24-Dec-04 23:59 
GeneralPrint Special Unicode Char In RichEdit Pin
Polytheus24-Dec-04 3:23
Polytheus24-Dec-04 3:23 
Generalconvertion of a count to DateTime format Pin
sam_software24-Dec-04 3:12
sam_software24-Dec-04 3:12 
GeneralRe: convertion of a count to DateTime format Pin
John R. Shaw25-Dec-04 7:52
John R. Shaw25-Dec-04 7:52 

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.