Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Right alignment in CString::Format

Posted on 1997-05-29
1
Medium Priority
?
898 Views
Last Modified: 2008-03-03
I want to use CString::Format to pack the items and then print it out. The items are not fix in length.
For example:

CString str, item1, item2;
int i;

for (i= 0 ; i<50 ; i++)
{
...
...
str.Format("%6s %15s", item1, item2);
pDC->TextOut(point.x, point.y, str);
...
}

item1 and item2 will change and have different length all the time.
How can I make the items to right alignment in CString::Format?
0
Comment
Question by:edward95
[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 1

Accepted Solution

by:
jmmougeolle earned 0 total points
ID: 1163750
This one is really easy, what you got to do is to use 2 Padded string as following:

#define TOTAL_LENGTH_ITEM1 6
#define TOTAL_LENGTH_ITEM2 15

CString strAddedWhiteSpaceForPaddedItem1(' ',
                     TOTAL_LENGHT_ITEM1-strItem1.GetLength());
CString strAddedWhiteSpaceForPaddedItem2(' ',
                     TOTAL_LENGHT_ITEM2-strItem2.GetLength());
str.Format("%s %s",
        strAddedWhiteSpaceForPaddedItem1 + strItem1,
        strAddedWhiteSpaceForPaddedItem2 + strItem2);


and that's all folks!


May the MFC be with you...
jmmougeolle@calva.net strikes back!






0

Featured Post

Industry Leaders: 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

688 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