CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2017
    Posts
    48

    What's wrong with my std::ostringstream usage

    Tried to my update my window title with some performance metrics for my vulkan renderer with std:stringstream. When i run it tells there's access violattion leading to xtring file funtion size_t length(_In_z_ const _Elem* const _First) where the the _First parameter is null as shown on picture below. Here's the code i wrote
    Code:
    void ApplicationBaseVk::UpdatePerformanceMatrics()
    {
    	std::ostringstream osstream;
    	osstream << mWindowTitle << " Frametime : " << mDeltaTime << " FPS : " << 1.0f / mDeltaTime;
    
    	glfwSetWindowTitle(mWindow, osstream.str().c_str());
    }
    Name:  Untitled.jpg
Views: 35
Size:  29.3 KB
    Or maybe i've done in wrong way.I'm running latest msvc 2022.Sorry for my bad english.Thank you

  2. #2
    Join Date
    Oct 2017
    Posts
    48
    Update: I tried on simple console app and it works fine.This confusing me.
    Code:
    #include <iostream>
    #include <sstream>
    
    int main()
    {
        int i = 0;
        std::ostringstream ss;
        ss << "Hello" << i << "\n";
    
        std::cout << ss.str().c_str();
    }
    Name:  Untitled2.jpg
Views: 25
Size:  19.7 KB

  3. #3
    Join Date
    Oct 2017
    Posts
    48

    Re: What's wrong with my std::ostringstream usage

    Update : It turns out I forgot to do
    Code:
    mWindowTitle = appName;
    in my app initialization function.Foolish me. Sorry for the trouble. Have a nice day folks.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,631

    Re: What's wrong with my std::ostringstream usage

    We've all made stupid mistakes at least once, twice...
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.2.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured