|
My problem is that i need to do some addition, subtraction, and multiplication on a number and then display the result in a textbox or label or something like that so that it is displayed in the window. I have been trying to find how to convert from an int to a system::string (if it is even possible) but could not find anything. Am i going about this wrong just cannot figure out how to do it correctly. I am using microsoft visual c++ express edition 2005 beta 2.
I have tried searching the web for anything like this and could not find anything that would work. I have been working on this for over a week now and connot figure it out. I am new to programming so it is probably pretty simple but i cant find any help on this. Any help that anyone could offer would be greatly appreciated.
-Kyle
|
|
|
|
|
system::string means you're using managed C++, not normal C++ ? system::string has a Format method to do what you want. If you were using C++, then istringstream or *shudder* sprintf would convert int to string, or CString::Format ( from memory ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i am using managed c++. if you could include a sample code of how to use the System::String Format function it would help out greatly. i looked at it but it asked for a System::String and a System::Object what would i put for the each and where does the int variable go?
if i use a textbox named txt and an int variable named num, would it be:
txt->Text->Format(txt->Text, num);
is this right or am i way off??
thank you for the help.
-Kyle
|
|
|
|
|
The system::string is the format string, and the object is the object to format. You can pass in as many objects as you like, they are numbered from 0.
txt->Text = System::String::Format("{0}", num);
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I tried that a few different ways some ways compiled but did not do what i wanted it to and the way that was posted gives me the following error:
error C2664: 'System::String ^System::String::Format(System::String ^,System::Object ^)' : cannot convert parameter 1 from 'int' to 'System::String ^'<br />
1> No user-defined-conversion operator available, or<br />
1> No standard conversion exists from the boxed form of the arithmetic type to the target type
and would not compile.
i searched the web and found the stringbuilder class and was wondering if this would do what i wanted it to.
- Kyle
|
|
|
|
|
A string builder will do what you want, but it's overkill.
The basic problem is that MC++ is a crappy kludge, I'm glad I've never used it in depth. You need to manually box your integer for string::format to work. You do it like this:
int n = 2003;
Console::WriteLine(System::String::Format("{0}", __box(n)));
That is, this is an example of how to box your integer.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
if i try this it gives me the following error:
error C2227: left of '->ToString' must point to class/struct/union/generic type<br />
1> type is 'int'
- Kyle
|
|
|
|
|
|
Thank you Jose Lamas Rios. The num.ToString() worked.
I had been tring for quite some time to figure that out thank you very much.
- Kyle
|
|
|
|
|
|
i have sdk netmeeting3, i want to edit its. but i can't edit its with class wizart on VC++, can i?
|
|
|
|
|
You cannot edit the SDK, no. You can merely use the headers and lib files to link to it, so your code can call it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am learning Visual C++.net and have found that WinExec is no longer used/supported. I am trying to create a Windows Form employing a combo box. I want the user to select an item from the drop down list and have them run a program when the run button is clicked. How do I get The SelectedIndexChanged event to fire whenever the user selects a new program? Thanks for your inputs.
RRL
|
|
|
|
|
cupdoze wrote:
have them run a program when the run button is clicked
If that's the bit you're stuck on, the answer is ::ShellExecute.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
cupdoze wrote:
have found that WinExec is no longer used/supported.
In continuation With Mr. Graus,
you can refer this article too.....
http://www.codeproject.com/system/newbiespawn.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
can give some example of source code or project to write the server and client programming
|
|
|
|
|
I searched this site by typing 'client server' in the search dialog you can see just below the Code Project logo above, and found this[^].
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
After downloaded the server and client source code, I do not know how to build 2 project that one is for client and another is for server. can give some guide to build it? I really weak in computer programming and never touch Visual C++ before..
|
|
|
|
|
Are you being asked to do this by your boss or your teacher ? It's a really significant task if you've never used C++ before, if you can abandon it for something simpler, that would be sensible.
Why can't you build it ? What happens ? All you need to do is open the project and choose 'build', assuming you have the right version of VC++ ( I'm not sure which the project uses, actually )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's the inevitable...
I wrote a menu in the resource file and I entered it into the CreateWindowEx function call and it shows up. I also added code to the message handler to catch clicks. However, when I click items, nothing happens. Here's the handler:
switch (Msg) {<br />
case WM_COMMAND: {<br />
HandleMenuFunctions (hWnd, wParam);<br />
return 0;<br />
} break;<br />
default: {<br />
return DefWindowProc (hWnd, Msg, wParam, lParam);<br />
} break;<br />
}
HandleMenuFunctions is just a function that has another switch to do different things based on the menu item selected:
void HandleMenuFunctions (HWND hWnd, WPARAM wParam) {<br />
switch (LOWORD(wParam)) {<br />
case ID_FILE_QUIT: {<br />
MessageBox (hWnd, "Posting Quit Message now", "Notice", MB_ICONINFORMATION);<br />
PostQuitMessage(0);<br />
} break;<br />
default: { MessageBox (hWnd, "Encountered unknown menu ID", "Notice", MB_ICONSTOP); } break;<br />
}<br />
}
(excuse that smiley face, that should be a PostQuitMessage(0); call.)
Also, when I go to click the menu, it only shows me the popup menu under File every other time. The other times I click, the menu just loses focus. I don't know if that's important or not. Thanks in advance.
edit: I put breakpoints on that first WM_COMMAND case to see if the message is ever captured and it isn't. Either I'm catching the wrong message or something is wrong with the menu. I noticed that there are ways to declare a menu when I register the class in WNDCLASSEX and also when I call CreateWindowEx. I tried only declaring the menu when I register the class and the menu doesn't show, but when I declare it only in CreateWindowEx, it shows up. That might be important too.
solution: I fixed the problem, it had to do with my main message loop, it also fixed the thing where the menu loses focus. I removed the PeekMessage call and just let GetMessage get the message. Here's what I ended up with:
while (GetMessage(msg, NULL, 0, 0)) {<br />
if (msg->message == WM_QUIT) {
return ((int) msg->wParam);<br />
}<br />
TranslateMessage(msg);<br />
DispatchMessage(msg);<br />
}<br />
|
|
|
|
|
What does this error mean and how to solve it?
fatal error C1010: unexpected end of file while looking for precompiled header directive
|
|
|
|
|
If you are using mfc, you need to include "stdafx.h" as the first in your cpp files.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
To elaborate on the prior answer - the stdafx.h file is included BEFORE any other header in every file of a standard MFC project. Any headers you include before stdafx will be ignored. This most typically becomes a problem when you import a non MFC C++ file into your project. It's C++, the compiler can handle it, except that it's expecting to see standard headers. The stdafx header is full of includes, and if you don't need it for that file, or for any files in general, you can change your project settings from using standard headers, to a setting where you specify that the file is stdafx.h, and if you don't include it in a source file, the compiler will just allow it, and compile that file without using the standard header.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
can someone plz give me a tutorial on how to accessing Paradox useing ADO.
i'd like to do it completely in Win32/SDK also
Thanks In Advance,
bin e
|
|
|
|