Runtime error in streambuf

This is a discussion on Runtime error in streambuf within the C++ Programming forums, part of the General Programming Boards category; ok this is weird to describe...i have a recursive function that returns a value and then i print out that ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Runtime error in streambuf

    ok this is weird to describe...i have a recursive function that returns a value and then i print out that value to the screen using cout...

    although i can confirm that the return value from the function is correct...when i try to do the cout the screen window keeps on printing several lines of text which basically when i look at them are drive extensions to several folders in my directory...

    plus this line in _streambuf.h is highlighted:
    Code:
      // Write __n characters.
      streamsize sputn(const char_type* __s, streamsize __n)
        { return this->xsputn(__s, __n); } //this line
    im reading lines from a text file and then after reading each line i call my function and use cout...

    does anyone know what could be the source of this?

    Regards,

    Farooq

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    another thing...this only happens for the second line in the file...the file is like this:
    Code:
    no,no,yes,no,some,high,no,yes,french,10-30
    no,no,no,no,full,high,no,yes,italian,>60
    i checked the return values from the function of both lines and they are correct...the first line's result is printed out right...the second line's result gets messed up even though the function output is right...

    Regards,

    Farooq

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    if it'll help here's the code:

    FUNCTION:
    Code:
    string Decision::classify(string treenodename)
    {
            //cout << treenodename << '\n';
            map <string, TreeNode *>::iterator j = treenodes.find(treenodename);
    
            map <string, string>::iterator k = (j->second)->ClassMap.find(testdata[(j->second)->NodeID]);
    
            if( k == (j->second)->ClassMap.end() )           
            {
                    map <string, string>::iterator l = (j->second)->NodeMap.find(testdata[(j->second)->NodeID]);
                
                    classify(l->second);                      //recursive call for next node along branch
            }
            else
            {    
                    return (k->second);                       //return the class name
            }
    
    }
    MAIN CODE:
    Code:
            int x = 0;
            char word[MAX_STRING];
            string temp;
    
            ifstream in("test_data.txt");
    
            while (!in.eof())
            {
                    in.getline(word, MAX_STRING);
                    replace(word,word + MAX_STRING,',',' ');
    
                    istringstream parser(word);
                    while(parser >> temp)
                    {
                            strcpy(testdata[x], temp.c_str());
                            x++;
                    }
    
                    x = 0;
    
                    cout << decision.classify(root) << '\n';
            }
    
    
            in.close();

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    if i try to output to a file...this is what should be printed:
    Code:
    YES
    NO
    and this is what is printed:

    Code:
    YES
    h(
    again the output from the function for each line is YES and NO...i have confirmed this...

    Regards,

    Farooq

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    sorry for bumping my thread like this...found out one more thing...no matter which case i tried, the return from the function if correct...so i know the rest of the program is not messing up...if i go into the function and get a return on the first step (without any recursion) the error is not there...but in the case of recursion though the outputs are correct...the program gets the runtime error...

    now when ive changed the file to one with 2 lines the error is access violation (same as before) but this time the highlighted line is in: _alloc.h
    the line is:
    Code:
      static void * _STLP_CALL allocate(size_t __n) { return (__n > (size_t)_MAX_BYTES) ?  __stl_new(__n) : _M_allocate(__n); }
    what's going wrong?

    Regards,

    Farooq

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Runtime formation and execution at runtime
    By Soham in forum C Programming
    Replies: 17
    Last Post: 08-27-2008, 08:45 AM
  2. link with C runtime library
    By George2 in forum C++ Programming
    Replies: 26
    Last Post: 02-05-2008, 12:56 AM
  3. Visual Studio and .Net Runtime Framework dependency
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-08-2007, 07:52 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21