> The code below works fine when and displays the counter as required,
> however when i run the program with the debugger i get an odd string
> of characters output instead of numbers:
> 
> îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþî
> 
> Here is the code, any idea what might be going wrong here??
> 
> function call:
> countOutp->value(GetCountString());  //output as c style string
> 
> Implementation:
> 
> const char* ListBuilder::GetCountString()
> {
>     string outputStr;           //temp output string
>     ostringstream countVal;     //convert int value to string
>     countVal << count;          //convert count integer to char string
>     outputStr = countVal.str(); //assign contents to string object
> 
>     return outputStr.c_str();   //return as c style string
> }

Your string goes out of scope as soon as the function returns (you have created 
it on the stack, local to the function) so anybody trying the read the returned 
c_string later on will just get garbage... As you have noticed.

If this is what you want to do, you need to declare string outputStr as static, 
so that it will persist after your function returns.





SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to