Results 1 to 4 of 4

Thread: A really weird thing happening

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Italy
    Posts
    9

    Question A really weird thing happening

    I use Visual C++ and I have this code as a member function of a class I created:
    PHP Code:
    ifstream DatFile("C:\\analize.dat");
    DatFile.get(m_AppPath,100);
    DatFile.close(); 
    In the analize.dat file there is a path to an application and m_AppPath is an array of 100 char.

    The problem is that the program works well when I compile it in the Debug mode, but give me a system error when I run the version compiled in release mode.

    The program compiled in the release mode works well if I assign directly a value to m_AppPath, for example:
    PHP Code:
    ifstream DatFile("C:\\analize.dat");
    DatFile.get(m_AppPath,100);
    DatFile.close();
    m_AppPath="C:\\dir\\app.exe"
    Does someone know why the first code work only in debug mode ?
    Thanx

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Make m_AppPath an array of 101, then after the .get(m_AppPath, 100) you need to put the null terminator on (if there isn't one already):
    Code:
    m_AppPath[100] = '\0';
    Actually, why can't you just use a string for the path?
    Code:
    #include <string>
    
    // in class def
    std::string m_AppPath;
    
    // your code
    ifstream DatFile("C:\\analize.dat");
    getline(DatFile, m_AppPath);
    DatFile.close();
    For this you'll need to be using the standard iostreams (in <iostream> and <fstream>, not <iostream.h> and <fstream.h>).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Italy
    Posts
    9
    Ok, thanx
    However, why does my code work only in debug mode ?
    Last edited by Fumozzo; Jun 20th, 2002 at 12:32 PM.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Because in debug mode, there is automatically a little more space allocated, so that such errors don't simply occur but rather can be traced. You're writing in a forbidden area, the app would eventually warn you about this.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width