|
No one know?
|
|
|
|
|
I want to format 3 digit numbers as follows
if number is 6 then add "00" before number; SNumber = 006
if number is 15 then add "0" before number; SNumber = 015
CString givenTEXT;
GetDlgItemText(IDC_ID, givenTEXT);
int TEXTvalue = givenTEXT;
CString tempTEXT;
if (TEXTvalue < 10)
{
tempTEXT="00" + TEXTvalue;
}
else if(TEXTvalue < 100)
{
tempTEXT="0" + TEXTvalue;
}
else
{
tempTEXT = TEXTvalue; //error: "=" operator is ambiguous
}
if i change the last line to
tempTEXT = "" + TEXTvalue;
it compiles but tempTEXT is all screw up : "..\include\Atlexcept.h"
|
|
|
|
|
Try this.
int i = 15;
CString str;
str.Format("%03d", i);
-Saurabh
|
|
|
|
|
I've tried the conversion routines and still get errors. I receive from an edit box a number. I want to add something to that number and then put it into a CString. can someone show me a code example that works Please. I can get the number find but I can't add something to it and then put it back into a CString.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I am sorry, what exactly is the problem? Perhaps some code you tried will help.
-Saurabh
|
|
|
|
|
For instance : int a = 42; CString str; int tmp;(pEdit already established) pEdit1->GetDlgItemText(str); now str holds the value the User typed which was NOT a number. but the representation of a number in character format. Now tmp = _tstoi(str); WORKS it changes the character to a number and puts it in tmp(an integer). but my question is How do I do the reverse? How to I get an integer valve into the CString(ie str)?
I've tried these functions: _itot_s, _itoa_s, and _itoa and they all give a long error message basically saying the str cannot be transfered to a char*
I know there is something that works, but I can't recall what it is.
I just want to put an integer value into a CString after I have converted one from the User's entry.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Okay I think the problem is _itot excepts second argument to be either wchar_t* or char* depending whether unicode is defined or not and it cannot automatically convert from CString to char* or wchar_t*. I don't use much MFC so not sure if there are function in CString to automatically do this but you can try something like this:
int i = 42;
CString str("50");
int temp = _ttoi(str);
temp += i;
TCHAR buffer[50];
_itot(temp, buffer, 10);
str = buffer;
-Saurabh
|
|
|
|
|
works until the last statement: str = buffer; at this point buffer does indead have the value I want, but I get an Access violation error when the assignment operator in CString tries to assign buffer's value to the CString(ie str).
A C++ programming language novice, but striving to learn
|
|
|
|
|
check CString format function
CString tmp;
int a = 5;
tmp.Format("%d Hey ", a);
Hope this helps.
|
|
|
|
|
I get this error: "Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"
A C++ programming language novice, but striving to learn
|
|
|
|
|
That should be:
CString tmp;
int a = 5;
tmp.Format(_T("%d Hey "), a);
Here's a tip:
Choose a string character type and stick with it.
The three common choices are
char (ANSI)
wchar_t (Unicode)
TCHAR (Generic - either char or wchar_t based on build configuration)
MFC uses generic types and, except for OLD APIs, so does Windows, so if you're using MFC,
generic is probably the best choice - unless you want to have to conver strings every
time you call a Windows or MFC API.
CString is also a generic type - it's either a CStringA (ANSI/char) or
CStringW (Unicode/wchar_t) depending on the build configuration.
If you choose to use the generic types, use them everywhere.
That means:
Use the Generic Text Mappings[^]
Wrap your string literals with the _T() macro
Use CSring instead of CStringA or CStringW
IMO, this stuff should be second-nature. You shouldn't have to think about it.
It's VERY worthwhile to take the time to understand it completely.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi,
I have the following issue:
#include <time.h>
....
struct tm tm;
if(strptime("2001-05-21", "%Y-%m-%d", &tm) == NULL)
{
//Some error processing
}
But I seem to be getting the following error when I compile, Can someone please tell me what I am doing wrong?
error C3861: 'strptime': identifier not found, even with argument-dependent lookup
|
|
|
|
|
correction
#include < time.h >
|
|
|
|
|
That is because strptime is not available in VC++. You can either try something else or use a open source version like strptime[^].
-Saurabh
|
|
|
|
|
Hi,
I created an SDI application(MFC) with an Acceletor Key (F1) that calls a Modeless Help Dialog. However, I would like to be able to select the F1 VK again so that it would close the Help dialog. This works if I move the focus from the help dialog to the main application window. Any ideas why this is happening. I do recall seeing this work if the dialog window is created using the WIN32 API CreateWindow.
Thanks
|
|
|
|
|
Try to get the KeyDown event and if it is the key you need, then call the method of the main window.
DialogBoxes doesn't share all the features of the application that called him.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Write a program that prompts the user to enter text from the keyboard. The text is read until Ctrl+Z is entered, i.e., the end of file is reached. The program should count the frequency of each digit and of each letter of the alphabet (but it should not distinguish an uppercase letter from a lowercase letter). When the user finishes inputting text, the program should display each letter and its frequency in a table format. Also, the number of special characters (i.e. not letters nor digits) should be reported.
Hint: Declare an array of counters, one for each letter and for each digit. Use the letter and the digit itself as the subscript that determines which array element to increment. To do this the program must convert the letter and the digit to the corresponding subscript (the ASCII values of the lowercase letters are 97 – 122, the ASCII values for the uppercase letters are 65 – 90 and the ASCII values of the 10 digits are 48-57).
Example:
The following input:
Th1s 1s a test.^Z
Should produce the following result:
1 2
a 1
e 1
h 1
s 3
t 3
Special symbols:4
Additional requirements:
- the program cannot use global variables
- the program must contain at least two functions called count and printReport; formal parameters can be added to these functions (if necessary)
i need a code ASAP plz any help is appreciated. ive been working this code for days and its almost due.
|
|
|
|
|
homework ... what have you done ?
This signature was proudly tested on animals.
|
|
|
|
|
Maximilien wrote: what have you done ?
Rhetorical question?
led mike
|
|
|
|
|
You missed the following sentence: michael1201
wrote: ive been working this code for days and its almost due.
He just needs a little help: semicolons here and there.
BTW: ASAP plz!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no...that would be "OMG what have you done?".
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
michael1201 wrote: i need a code ASAP...
Check your inbox. I sent it as fast as I could. Sorry for the delay.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
michael1201 wrote: i need a code ASAP plz
Done: visit www.cpallini.free.homework.com[^]
BTW what have you done so far. What is still missing? What are you troubles about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Only Days??
Most Software takes Months, (at least) so get used to it and don't give up after days. Hint: In future: Start Earlier.
Success
Bram van Kampen
|
|
|
|