Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange C++ std::string behavior... How can I fix this?
    primarykey
    data
    text
    <p>This is driving me nuts. I have been at it for over 2 hours trying to figure this out...</p> <p>Here is my problem. I am working on a fairly large program that works with Bayesian networks. Here is the main function:</p> <pre><code>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(net); //net.WriteFile("test.dsl"); return(DSL_OKAY); } </code></pre> <p>This all works fine. The problem comes when I want to print out a string:</p> <pre><code>using namespace std; int main() { //simple string creation string a = "test"; //should print out "test" cout &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(net); //net.WriteFile("test.dsl"); return(DSL_OKAY); } </code></pre> <p>Here is the output (just from printing the string a...):</p> <p>   ▀ÇΦy♠≈6 ♦</p> <p>What could be going on?</p> <p>UPDATE:</p> <pre><code>int main() { //simple string creation string a = "test"; //should print out "test" cout &lt;&lt; a &lt;&lt; endl; return(DSL_OKAY); } </code></pre> <p>still prints </p> <pre><code>▀ÇΦy♠≈6 ♦ </code></pre> <p><strong><em>BIG UPDATE:</em></strong> Here is the recent. I created a brand new project and pasted the code that Neil Butterworth posted (thanks btw). I ran the code and it printed correctly. Then I added the two .lib files to the Linker in the new project (smile.lib for the SMILE library, and wsock32.lib for socket use.)</p> <p>I tried the code again, and it printed the first "test" correctly, then it printed the giberish. It is a problem with one of the .libs I am linking together. I tried each on their own to see if they are just clashing, and it seems that the smile.lib library is causing the problem. I will need to go into their documentation and figure out why.</p> <p>Any ideas?</p> <p>Thanks all for the help</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload