Jump to content


fstream debug assertion failed


2 replies to this topic

#1 c0mputer-fr0d

    Member

  • Members
  • PipPip
  • 30 posts

Posted 21 January 2013 - 06:23 AM

This is in vc++ 2010 on windows 7
public: int Form1::ReadList(){
	    ifstream pile;
        int count = 0;
        char inputbuff[100] ={'\0'},*tok,*folder;
        String^ poo = textBox1->Text;
        char* fil = ConvertString(poo);
        progressBar1->Maximum = File_Quant(fil);
        pile.open(fil,ifstream::in);
        if(!pile.good()){
             MessageBox::Show("Please select a valid m3u and path", "Problem",
                 MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
       		  pile.close();
                 exit(1);
        }

public: char* Form1::ConvertString(String^ cnv){
            int length = textBox1->Text->Length;
		    char *out = new char[length+1];
	  for(int i = 0;i < length;i++){
		 out[i] = (char) cnv[i];
         out[length] = '\0';
        }
      return out;
        }
public: int Form1::File_Quant(char* fileloc){
		  int numfiles = 0;
          char enbuf[2];
          ifstream read;
          read.open(fileloc,ifstream::in);
          read.getline(enbuf,1,'\n');
          while(!read.eof()){
   	  read.getline(enbuf,1,'\n');
             numfiles++;}
         read.close();
	    return numfiles;
        }

gives me,
debug assertion failed
expression: stream != NULL

and talks about fclose.c when I'm not even calling fclose and I'm checking wheather it opened successfully on the next line
which really confuses me because if I have a file that doesn't exist it doesn't give me this but when its a legitimate file I get it its quite a puzzle.
I really need help , please and thanks.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationSanta Clara, CA

Posted 21 January 2013 - 07:30 AM

If you run your program within the debugger, the assert should give you the opportunity to break and look at the call stack, so you'll see where in your code this is coming from. Presumably you're seeing fclose because the std::ifstream uses it internally.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 c0mputer-fr0d

    Member

  • Members
  • PipPip
  • 30 posts

Posted 21 January 2013 - 11:28 PM

I still haven't figured this one out any help is wanted.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users