473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

C++ formatting

Hi,

I have to display a string in a box in the following format:

Phase<SPACEEE>:
b<SPACEEEEEE>:
Di<SPACEEEEE>:
qi<SPACEEEEEE>:
Forecast ended by :

Thus everthing should be neatly arranged according to the length of the biggest string in this group which is Forcast ended by.

I hope I could explain the problem clearly.

How can I format the string beautifully?

Thanks.

Regards,

Amol
Aug 27 '07 #1
3 1289
RRick
463 Expert 256MB
In C++, the iostreams have methods and functions that control the formatting of strings and numbers. Play around with the following and you should be able to get the formatting you want.
Expand|Select|Wrap|Line Numbers
  1. std::cout << std::left  << std::setw( 10) << "hello" << "--" << std::endl
There is also std::right and std::setfill( char). Some of these functions have a short life(i.e. setw) and some stay until reset (i.e. left)
Aug 27 '07 #2
Dude,

Thanks. But I am using MFC and I have to format the string using CString.Format().

So, it happens to look something like this:

strAnnotation.Format("Phase:%s\r:%1.1e\rDi:%1.1e(p er day)\rQi:%7.2f(m^3/day)\rTi:%s\rTcutof, value1, value2, value3, value4, value5)

Any ideas??

Regards,


In C++, the iostreams have methods and functions that control the formatting of strings and numbers. Play around with the following and you should be able to get the formatting you want.
Expand|Select|Wrap|Line Numbers
  1. std::cout << std::left  << std::setw( 10) << "hello" << "--" << std::endl
There is also std::right and std::setfill( char). Some of these functions have a short life(i.e. setw) and some stay until reset (i.e. left)
Aug 27 '07 #3
RRick
463 Expert 256MB
Those format statements look suspicously like C style format statements. Try changing the %s to %15s or %-15s. That will justify and set the width of that string. If you want the numeric 15 to be a variable, you'll have to consult the doc for Format.
Aug 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
1
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
8
by: gopal | last post by:
Hi I am trying to write to log file but the formatting of string is not properly aligned in log file result The results looks some thing like this OK move.xml Successful OK ...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.