-
February 10th, 2002, 02:04 PM
#1
Str() vb equivilant in C++?
Hello-
Just a quick question, is there an equivilant to the VB function str() which takes an integer, long, or float, and converts it into a string? Or, will I have to write my own in order to accomplish this task. Many thanks.
Brendan
-
February 10th, 2002, 02:21 PM
#2
Re: Str() vb equivilant in C++?
Using CString...
CString MyString;
MyString.Format("%d", MyInteger);
MyString.Format("%ld", MyLong);
MyString.Format("%f", MyFloat);
or Using character based array...
char MyBuffer[200];
wsprintf(MyBuffer, "%d", MyInteger);
wsprintf(MyBuffer, "%f", MyFloat);
// Etc..
Hope this helps,
- Nigel
-
February 10th, 2002, 02:23 PM
#3
Re: Str() vb equivilant in C++?
Thank you very much for your reply!
Brendan
-
February 10th, 2002, 02:26 PM
#4
Re: Str() vb equivilant in C++?
Brendan, if you include stdlib.h you can use
itoa - integer to asci
atoi - asci to integer
There are also equivs to long and float.
char buf[20];
int num = 100;
itoa(num,buf, 10);
cout<<"string: "<<buf;
-
February 10th, 2002, 02:46 PM
#5
Re: Str() vb equivilant in C++?
Thank you, both are good ways for what I need to do.
Brendan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|