|
|
What's the easiest way to drop the 0 on .233 floating point variable when displaying.
I'm using visual studio .net c++ for compiler.
Thanks!
|
|
|
|
|
using the format string "%4.3f" should do the trick.
Steve
|
|
|
|
|
Thanks, do you have an alternative solution, I'm not allowed to use printf type functions in my visual studio.net c++ program code.
Thanks!
|
|
|
|
|
I'm surprised that you are not allowed to use something like
CString str;
float xnum = 0.123;
str.Format("%4.3f", xnum);
[equivalent to char str[8]; sprintf(str, "4.3f", xnum);]
-------------------------------
but you can also use _fcvt
int decimal, sign;
char *buffer;
double source = 0.123;
buffer = _fcvt( source, 3, &decimal, &sign);
--------------
result:
buffer = "123"
decimal = 0;
sign = 0;
from MSDN:
"The _fcvt function converts a floating-point number to a null-terminated character string. The value parameter is the floating-point number to be converted. _fcvt stores the digits of value as a string and appends a null character ('\0'). The count parameter specifies the number of digits to be stored after the decimal point. Excess digits are rounded off to count places. If there are fewer than count digits of precision, the string is padded with zeros.
Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec parameter points to an integer value; this integer value gives the position of the decimal point with respect to the beginning of the string. A zero or negative integer value indicates that the decimal point lies to the left of the first digit. The parameter sign points to an integer indicating the sign of value. The integer is set to 0 if value is positive and is set to a nonzero number if value is negative."
-------------------------
Note that you will get last digit rounding.
You did not indicate if you have to manually do the conversion.
Steve
|
|
|
|
|
Im still new at this. Ive been trying for days, but I still cannot populate a list box from a text file. I need a method. Ive been instructed to read into CList and CStdioFile classes. Prying into the help file to understand this, I came away more confused than ever.
Surely, this is a standard operation! Isn't there a hard and fast method for doing this?
Help! Im desperate!
Travis
|
|
|
|
|
macrophobia wrote:
Isn't there a hard and fast method for doing this?
No.
Permit me to offer an analogy: millions of people use their car to drive to work. Their route is usually a fixed one (from home to work). Yet, no car offers a magic button labelled "Drive to work". You have to:- Start the car.
- Navigate your route to work (by using the accelerator, brake, gears and steering wheel).
- Park the car.
- Turn off the engine.
It's the same with your programming problem. You need to:- Open the file for reading.
- Read each line (see
CStdioFile ).
- Add each line to the list box (see
CListBox ).
- If there are more lines to read, return to step 2.
- Close the file.
That's what programming is all about. Lots of little instructions that allow you to perform a task.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Im coming to that conclusion every day. At least with Assembly language, I expected it. I guess Ive been hoping that all the magic routes have been paved for me with C++.
Thank you for your reply. I'll use your steps to help me put this thing together.
Travis
|
|
|
|
|
Good luck! And feel free to ask questions - we're here to help.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thank you for making me feel welcomed! I hope to help people some day. (By the looks of things, it will take years! There is alot to know!)
Travis
|
|
|
|
|
That is not necessarily true, just look at how much you have learned in a short period of time...
Steve
|
|
|
|
|
Thats true. I have learned quite a bit. Thankfully, you gave me the help that I needed to get over a snag. This programming stuff isnt too bad if you can get a lifeline now and then.
In fact, it's pretty cool. Well, when I reach some level of mastery, perhaps I can use my real name and help others too.
Ill look for your excellent posts in the future!
Travis
|
|
|
|
|
There is no method to directly fill a list box from the contents of a file. You have to open the file, read lines, add each line to the list box and close the file.
Easiest way is to use the class CStdioFile and
then use the method ReadString. Like:
====================
CStdioFile m_File;
CString m_strLine;
m_File.Open("FileName", CFile::modeRead, NULL);
if(m_File.m_pStream != NULL) /* File opened? */
{
while(m_File.m_pStream != NULL)
{
if(m_File.ReadString(m_strLine))
m_cListCtrl.AddTail(m_strLine);
else
{
m_File.Close();
break;
}
}
}
Steve
|
|
|
|
|
Thank you for this info!
This looks like great stuff!
Please correct me on any misinterpretations I am about to make.
CStdioFile m_File;<br />
CString m_strLine;
I see from the code that m_File is an object of CStdioFile and m_strLine is an object of CString...
m_File.Open("FileName", CFile::modeRead, NULL);<br />
if(m_File.m_pStream != NULL)
take the CStdioFile object (m_File), call it's inherited function (Open), then check to see that the file was successfully opened.
{<br />
while(m_File.m_pStream != NULL)<br />
{
while the file is open and not at the end of its text...
{<br />
if(m_File.ReadString(m_strLine))<br />
m_cListCtrl.AddTail(m_strLine);
...read from the text file and write to the listbox...
else<br />
{<br />
m_File.Close();<br />
break;<br />
}<br />
}<br />
}
...finally close the file and end.
Again, Thank you. But I have two small questions:
1. Does the "Filename" have to point to the full path of the text file, or can I just include it in the build as a resource file?
2. If I have created an object for my listbox (named m_choices), do I substitute that name where you have used "m_cListCtrl"?
Thank you for bearing with me. You may be saving my life!
Travis
|
|
|
|
|
You are a great help!
Thank you, Steve!
Ive got some new wind in my sails!
I studied deeper into CString and CStdio. I fiddled a bit.
I found m_cListCtrl.AddTail(m_strLine); was giving a little trouble...I changed it to m_choices.AddString(m_strLine);
...and BAM! My listbox is functional!
Thank you sooo much. I bet someone else will have the same problem and find this solution! This is great!
Travis
|
|
|
|
|
Hi,
I was wondering if anyone knows why a process would show up in the process list in the short dos 8.3 format and not the long, full name format?
My process shows up as proc~1.exe. How do I get it to show up as process.exe?
Thanks.
|
|
|
|
|
|
Hi all,
I am trying to make a program which does the folowing:
every 1 second, it should click the mouse, so if the mouse is on the START menu , it should go up and show the menu, and if it is on the system menu (X) the window should close...
I used the following method:
i used WidnowFromPoint and GetCursorPos APIs to get the window at which the cursor is over.
and I used SendMessage() with WM_LBUTTONDOWN and with WM_LBUTTONUP to act like a mouse click.
this work well for command buttons and some windows, but when it comes to menus and taskbar buttons it does not work well.
I NEED IT TO ACT EXACTLY AS IF I REALLY CLICKED THE MOUSE BUTTON ON THE POINT AT WHICH THE MOUSE IS OVER!!!
any ideas?
thanx in advance,
Mohammad
|
|
|
|
|
|
Hi again. I got help from here before, and I hope to find some again. My problem is when I run the below program. While running, I can add fields to my queue, but when I try to run my writeAll function, it does the first list, then crashes. Any help would be appreciated.
proj5.cpp Code:
<code>
#include <iostream.h>
#include <string.h>
#include "class.h"
// #include "QUEUE.h"
// #include <iostream.h>
using namespace std;
template <class dT>
void writeAll(queue <dT>);
int main()
{
queue <string> nameQueue;
queue <int> numQueue;
char choice;
string name;
int num;
// template <class dT>
// void writeAll(queue <dT>);
do
{
cout << "A - Adds record to the queue" << endl;
cout << "V - View all records in the queue" << endl;
cout << "Q - Quits program" << endl;
cout << "Choice: ";
cin >> choice;
switch(choice)
{
case 'a' :
case 'A' : cout << "Players Name: ";
cin >> name;
nameQueue.enQData(name);
cout << "Players Number: ";
cin >> num;
numQueue.enQData(num);
break;
case 'v' :
case 'V' : writeAll(numQueue);
writeAll(nameQueue);
break;
case 'q' :
case 'Q' : cout << "Quit\n";
break;
default : cout << "Not a valid choice.\n";
} // end switch
} while(choice != 'Q' && choice != 'q');
return 0;
} // end main
// - - - - -
template <class dT>
void writeAll(queue <dT> theQ)
{ node <dT> * at = theQ.front;
do
{ cout << at -> data << endl;
at = at -> backward;
} while(at != NULL);
} // end writeAll
</code>
If you want me to post the "class.h" file, I would be more than happy too. Thanks for any help in advance.
|
|
|
|
|
Hi,
I have a problem that I don't really know where to start with, and I'm hoping someone are able to help me.
I have developed a program that relies heavily on GDI+, and mainly this works well. However I have experienced a bug when printing on a windows 98 machine with a HP 540 printer, where the page printed has the colors switched. That is, the areas I want white is black, and the other way around. I know that win98 is a long time ago, but this particular program aims at users in the school-sector, where brand new computers are a quite seldom sight, so I have to make it work.
What confuses me more, is the fact that nothing in the program itself seems to have any problems with the use of GDI+. I've installed the gdiplus.dll-file, and my program does what it's supposed to perfectly, including print preview.
On other test machines however, including my own, I have no problems printing perfectly...
This confuses med quite a bit, so any help would be appreciated a *lot*, even if it's only a clue on to where I should look.
|
|
|
|
|
HP drivers are often crap. See if there's an upgrade available before you waste too much time on it.
Shog9
I'm not the Jack of Diamonds... I'm not the six of spades.
I don't know what you thought; I'm not your astronaut...
|
|
|
|
|
OK, thanks for the tip, but I tried it with no luck. The driver was the latest driver available.
|
|
|
|
|
Who can tell me, how to compile project in VC++ .NEt which will include all neccesary dlls, and even .NET frameworks components.
Hayk
|
|
|
|
|
I want to give my Windows/Dialogs the look of Xp as you should have seen in the Yahoo Messanger when we install it.
If anyone of you can tell where should a start from I would be really thank full.
shahzad zafar siddiqui
|
|
|
|