Strange C++ std::string behavior... How can I fix this? -


This is driving me crazy I'm trying to understand ...

Here's my The problem is I'm working on a large program that works with the Bayesian network, here is the main function:

  using namespace std; Int main () {DSL_network net; InitializeNetwork (net); SetEvidence (net); Net.SetDefaultBNAlgorithm (7); Net.SetNumberOfSamples (80000); Cout & lt; & Lt; "Samples: \ t" & lt; & Lt; Net.GetNumberOfSamples () & lt; & Lt; Endl; UpdateEvidence (pure); //net.WriteFile("test.dsl "); Return (DSL_OKAY); }  

All this works well The problem occurs when I want to print a string:

  using namespace std; Int main () {// Simple string creation string a = "test"; // is called "test" COAT & lt; & Lt; A & lt; & Lt; Endl; DSL_network Net; InitializeNetwork (net); SetEvidence (net); Net.SetDefaultBNAlgorithm (7); Net.SetNumberOfSamples (80000); Cout & lt; & Lt; "Samples: \ t" & lt; & Lt; Net.GetNumberOfSamples () & lt; & Lt; Endl; UpdateEvidence (pure); //net.WriteFile("test.dsl "); Return (DSL_OKAY); }  

Here is the output (by printing the string ...):

▀ÇΦy ♠ ≈6 ♦

What could be What is happening?

update:

  int main () {// simple string creation string a = "test"; // is called "test" COAT & lt; & Lt; A & lt; & Lt; Endl; Return (DSL_OKAY); }  

still print

  ▀ÇΦy ♠ ≈6 ♦  

Large update : Here I have recently created a new project and paste that code which Neil Butterworth posted (thanks BTW) I ran the code and it was printed correctly. Then I added Linker to the new project in two projects. (Smiley.lib for smiley library, and wsock32.lib for socket use.)

I tried to redo the code, and print it before the "test" correctly, then it Printed giberish This is a problem with one of the .libs I am linking together. I tried my best to see myself that they are just teasing, and it sounds like a smile. The library is causing the problem.

Any thoughts?

Thanks for the help

thanks

this strange I always want to break this problem in the least case when you run it, what does the following program do?

  using namespace std; Int main () {string a = "test"; Cout & lt; & Lt; A & lt; & Lt; Endl; Return 0; }  

If this works, then something is wrong and you have to add it one line at a time until it fails. Then check that line lot carefully ("I'm hitting vibbits").

Depending on your editing, this can be used by a different string class. Try it:

  int main () {std :: string a = "test "; Std :: cout & lt; & Lt; A & lt; & Lt; Std :: endl; Return 0; }  

Update:

Since it works in a new project and not currently, check the following.

  • Make sure you are linking to the standard C ++ runtime.
  • Ensure that you do not form #define string as something else (and in the -destring = command-line option for the command compiler) .
  • Check behavior by using std :: string , not just string .

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -