fstream debug assertion failed

E3465662c70bd9bebf3f75223a7a5ce4
0
c0mputer_fr0d 101 Jan 21, 2013 at 06:23

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 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jan 21, 2013 at 07:30

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.

E3465662c70bd9bebf3f75223a7a5ce4
0
c0mputer_fr0d 101 Jan 21, 2013 at 23:28

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