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

  • Home
  • SEARCH
  • 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 8629141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:43:32+00:00 2026-06-12T08:43:32+00:00

Possible Duplicate: How do I convert a double into a string in C++? Convert

  • 0

Possible Duplicate:
How do I convert a double into a string in C++?
Convert double to string C++?

Total C++ and Win32 noob here playing around in Visual Studio 2012 land, so bear with me as I sometimes bite off more than I can chew 🙂

I have a Win32 app that’s simply set up a window using a peekmessage loop for real-time updating. The app runs okay and the Window shows fine. I’d like to print text to the Window title bar displaying the frames per second from a clock / timer class I was provided with.

I’ve yet to learn GDI / GDI+ or Direct2D & DirectWrite for outputting text and variable values to the client area, so for now I need a simple method of outputting some basic statistics to the Window and I figured the easiest way is to update the window title at this stage. My window class has a SetTitle method that takes a std::wstring so I was wondering how best to build a string from literal text and variable values such as double? As you can likely surmise I’m also unfamiliar with strings beyond the basic std:cout for Console-based apps.

Amazon tells me my Holy ‘Book of Petzold, 5th Edition’ is 3 days away so any tips will be greatly appreciated and you’ll make it onto my Christmas card list this year.

Thanks.

  • 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-06-12T08:43:33+00:00Added an answer on June 12, 2026 at 8:43 am

    After hunkering down and diving deeper into stream input and output, I finally found a solution that seems to work well.

    After including <sstream> in my project I created a std::wstringstream myString; object.

    In the real-time loop of my application I then had the following code to format the string and the value coming from the Clock class, which I then passed on to GDI to print out to the window client area:

      myString.clear(); // clear status bits
      myString.str(L""); // Clear the string for reuse
      myString << "FPS " << pGameClock->GetFrameRate();
    
      TextOutW(GdiDeviceContext, x_pos, y_pos,
               myString.str().c_str(),
               myString.str().length());
    

    During my learning process I took a quick detour into simple GDI text output because I initially had problems with updating my application window title property using the winapi SetWindowTextW function. It seems it doesn’t like being called at a high frequency in the main loop, resulting in my system becoming unresponsive when running the program, hence the need to learn basic GDI to outptut to my window client area rather than the window title bar.

    The pGameClock->GetFrameRate(); call by the way, is courtesy of an implementation of a high resolution clock and timer class designed by the talented Noel Llopis and presented in Game Programming Gems 4. (Thanks Noel).

    I’ve also discovered that there’s still plenty to learn about techniques for more performant string formatting & building techniques, especially when applied to real-time requirements in games but I suspect I’ll be better served heading over to http://gamedev.stackexchange.com (which I only recently discovered) for further questions and help?

    Books that helped this C++ noob better understand input and output streams:

    • Programming Principles and Practice Using C++, Bjarne Stroustrup
    • C++ for Everyone, 2nd Edition, by Cay Horstmann
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I convert string to double in C++? how can I
Possible Duplicate: How do I convert a string into an integer in objective C?
Possible Duplicate: converting a string into a double What is the optimal way to
Possible Duplicate: convert string to nsdate The NSString has following value '2012-07-11T15:59:16' I am
Possible Duplicate: Convert a number to the shortest possible character string while retaining uniqueness
Possible Duplicate: How can I convert a string to boolean in JavaScript? I have
Possible Duplicate: Fast way to convert a Bitmap into a Boolean array in C#?
Possible Duplicate: How can I convert String to Int? public List<int> GetListIntKey(int keys) {
Possible Duplicate: convert string to 2D array using php I have the string like
Possible Duplicate: Convert string to float in Objective-C I'd like to convert a string

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.