Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:43:54+00:00 2026-05-23T13:43:54+00:00

This is my function: string GaugeStr; void someFunction() { float pie = someFloat(); stringstream

  • 0

This is my function:

string GaugeStr;
void someFunction() {
    float pie = someFloat();
    stringstream ss (stringstream::in | stringstream::out);
    ss << pie;
    GaugeStr = ss.str();
}

When I run the function, it works properly. When I call it however for a second time (someFunction(); someFunction();, then my program crashes with a segmentation fault.

I tried putting stringstream ss (stringstream::in | stringstream::out); out of the function to make it a global variable, but the contents I want to send to GaugeStr get appended to ss. For example, if we assume that someFloat() always returns 1.2, then the second time I run the function, GaugeStr is set to 1.21.2.

So, I inserted ss.str("") in the function, but the program crashes again with a segfault.

What can I do to put the value of someFloat() is GaugeStr as a string without a segfault?

Exact Function

void CPU_BenchmarkFrame::OnButton1Click(wxCommandEvent& event) {
    float pie = PiAlgo (Gauge2);
    stringstream ss (stringstream::in | stringstream::out);
    ss << pie;
    wxMessageBox(_("Alert"), _("Sample Alert")); //To test where the segfault happens
    string GaugeStr = ss.str();

    wstring GaugeWid;
    std::copy(GaugeStr.begin(), GaugeStr.end(), GaugeWid.begin());

    StaticText2->SetLabel(GaugeWid);
}

Even more edits

The problem is one or more lines here:

    wstring GaugeWid;
    std::copy(GaugeStr.begin(), GaugeStr.end(), GaugeWid.begin());

    StaticText2->SetLabel(GaugeWid);

when I commented them the script worked normally.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:43:54+00:00Added an answer on May 23, 2026 at 1:43 pm

    @Bo spotted a good line (after the question was edited…). I agree.

    Here is a suggestion to fix it:

    GaugeWid.clear();
    std::copy(GaugeStr.begin(), GaugeStr.end(), std::back_inserter(GaugeWid));
    

    @kongr45gpen:

    I suspect a threading bug:

    • you are doing updates of a variable names GaugeStr (sounds like meter monitoring)
    • the code breaks on innocuous assignment to ……. a global.

    Sounds like a threading bug. Do you use threads, if so, you must appropriately lock GaugeStr or make it a thread local.

    Drop me a note if I need to expand on these, because at current I cannot be sure you are using threading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this function declaration in C#: void foo(string mystring) the same as this one
I'm going mental trying to figure out why this doesn't work: function hasOnlyWhitelistedCharacters(string) {
I have this following function in C++ CLI: void receiveData(String^ data) { } From
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
char *strtok(char *s1, const char *s2) repeated calls to this function break string s1
Whats this syntax useful for : function(String... args) Is this same as writing function(String[]
Example: /** * This function will determine whether or not one string starts with
My WCF service exposes this function public SerialNumberInfo GetSerialNumberInfo(string serialNumber) { } Is there
I have this function called ProperCase that takes a string, then converts the first
I have this function... private string dateConvert(string datDate) { System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo(en-GB);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.