Hi,
I am writing a compiled application using ROOT 5.18. I want to store a user specified file name as a string. Unfortunately, the program only seems to work when I hard code the file name as a string. When I try to get a user specified input and store it as a string, I get a STACKTRACE output and the program obviously crashes. I have the following #includes in the *.cpp file where my main() function is:
For both of these input methods, I do not have time to even begin typing a file name. Both failures occur the minute the cin prompt comes up. Any thoughts or help on this matter would be greatly appreciated.
I have found that a temporary fix can be used as a workaround for this issue. If I direct the user input to a char* object, I can then convert that char* input into a string input with a custom toString() function as follows.
// create an out string stream
std::ostringstream buffer;
// write the value to be converted to the output stream
buffer << toBeConverted;
// get the string value
return buffer.str();
}
[/code]
While this works, I am curious as to why directly handling user input with std::string causes so much difficulty in ROOT.
Andrew
This should a priori work. Which compiler (version) are you using? How did you compile your code? (I.e. I am suspect a mis-match in compiler switches).
I usually program in linux, so I am not sure what all this means. Also, some of the other people who use this computer have Chinese support enabled. I have no idea if this is a factor, but perhaps it will help shed some light on the issue. As you know before, it took me some time to figure out the _DEBUG preprocessor flag was set. Thanks again for your help.
Cheers,
Andrew
We build with: cl -O2 -nologo -FIw32pragma.h -MD -GR -G5 -EHsc-
The extra /Zi is most likely a problem (request debug symbols).
The missing ‘-GR’ is a possible problem. I don’t know what /FD does.
I have taken into account the suggestions you have made. However, I am still experiencing the same issue with string input. My updated flags are shown below.
Apparently the /GR flag is implied. I think the /FD flag needs to be removed, but I am not sure how manually edit the command line flags in Visual Studio. From the msoft documentation I found this about the /FD flag.
[quote]/FD ensures that the .idb file has sufficient dependency information. /FD is only used by the development environment, and it should not be used from the command line or a build script.
[/quote]
For now I think I have all the flags you do. I was also told by the C++ freenode channel that msoft officially states in their documentation not to use std + dll unless using std::vector.
also make sure that you are not using a debug version of ROOT together with your optimized program. Microsoft’s STL is incompatible between debug / non debug (=release). That could explain why you see crashes in STL code.