Apparently different behaviour assigning C string to std::string, for Relese/Debug
-
Hi, I think I'm getting different behaviours with the code below for Release and Debug compiles.
FILE* in ;
err = fopen_s (&in, fileName.c_str(), "r");
if (!in) {
std::cerr << "cannot open input file '" << fileName << "'" << std::endl;
return;
}
char buff[1024];
while (fgets(buff, 1024, in)) {std::string line=buff;
//...
line
is getting the characters ok when compiled in Debug. In Release though,line
is BadPtr. I guess I'm doing the initialization wrong, but I don't see why. -
Hi, I think I'm getting different behaviours with the code below for Release and Debug compiles.
FILE* in ;
err = fopen_s (&in, fileName.c_str(), "r");
if (!in) {
std::cerr << "cannot open input file '" << fileName << "'" << std::endl;
return;
}
char buff[1024];
while (fgets(buff, 1024, in)) {std::string line=buff;
//...
line
is getting the characters ok when compiled in Debug. In Release though,line
is BadPtr. I guess I'm doing the initialization wrong, but I don't see why. -
Hi, I think I'm getting different behaviours with the code below for Release and Debug compiles.
FILE* in ;
err = fopen_s (&in, fileName.c_str(), "r");
if (!in) {
std::cerr << "cannot open input file '" << fileName << "'" << std::endl;
return;
}
char buff[1024];
while (fgets(buff, 1024, in)) {std::string line=buff;
//...
line
is getting the characters ok when compiled in Debug. In Release though,line
is BadPtr. I guess I'm doing the initialization wrong, but I don't see why. -
Hi, I think I'm getting different behaviours with the code below for Release and Debug compiles.
FILE* in ;
err = fopen_s (&in, fileName.c_str(), "r");
if (!in) {
std::cerr << "cannot open input file '" << fileName << "'" << std::endl;
return;
}
char buff[1024];
while (fgets(buff, 1024, in)) {std::string line=buff;
//...
line
is getting the characters ok when compiled in Debug. In Release though,line
is BadPtr. I guess I'm doing the initialization wrong, but I don't see why.It's possibly a configuration issue. Meaning you've some configuration for Debug that you haven't done for Release.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
My excuses for not answering during the weekend. As suggested by some comment on the link you posted (thank you) the problem seems to be in the
fgets
function. It is storing senseless data inbuff
for Release, and then thestd::string
constructor can't make sense of it. I will try withstd::getline()
. -
It's possibly a configuration issue. Meaning you've some configuration for Debug that you haven't done for Release.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)