|
-
Jun 20th, 2002, 10:50 AM
#1
Thread Starter
New Member
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
-
Jun 20th, 2002, 11:54 AM
#2
Monday Morning Lunatic
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
-
Jun 20th, 2002, 12:00 PM
#3
Thread Starter
New Member
Ok, thanx
However, why does my code work only in debug mode ?
Last edited by Fumozzo; Jun 20th, 2002 at 12:32 PM.
-
Jul 3rd, 2002, 03:16 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|