?
Solved

String variable formats

Posted on 2004-08-21
1
Medium Priority
?
154 Views
Last Modified: 2013-11-20
In the following lines of code:

m_strFreeMemory.Format("%ld KB");
m_strMemoryLoad.Format("%d %%");

What does %d, %%, %ld do exactly?
0
Comment
Question by:fattumsdad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
Nass89 earned 200 total points
ID: 11862348
Hi,
The correct codes are:
m_strFreeMemory.Format("%ld KB", a);
m_strMemoryLoad.Format("%d",a);
it must contain an arguemnt for every '%' you use.

"%ld KB", is the format specifier and a is the arguement. The first part specifies which format to use to store the arguement in string.
example:
int a=255;
m_strFreeMemory.Format("%d ", a); --------> Display: 255
m_strFreeMemory.Format("%x ", a); --------> Display: 0xff
m_strFreeMemory.Format("%X ", a); --------> Display: 0xFF


A format specification has the following form:

%[-][#][0][width][.precision]type

See 'wsprintf' in MSDN for more info.

Good Luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question