|
I mis-typed it into the web-form, I assure you I spelled it correctly in the C++ program
|
|
|
|
|
First, I think you, like may others, are confused about how computers actually store characters. In the English language (non-Englich languages may be store differently), each character (both printable and non-printable) is represented by a numeric value between 0 and 255. (Actually, at the machine level, they are represented by their binary values, but I won't go there.) You cannot put an "A" into either a CString or a char buffer. Instead, the "A" is always convertd to its numeric value. Charts are easily available that show what these numeric values are.
The Basic languages that I've used (although very seldon) have a function to convert "A" to its numeric equivalent. This is not necessary in C/C++, because they are already represented that way. So, if you have a CString that contains "Hello", then what that CString really contains is six bytes of numeric values (the 6th byte contains the null terminator 0 ).
How do you convert a "byte" to an "int" ? Simple:
char c = 'A';
unsigned char = 'A';
int x = 'A';
int x1 = 64; // numeric value of 'A'
int x2 = c; // converts a char to an int.
CString s = "Hello";
char c1 = s[1]; // extract the letter 'e' from CString
char buffer[126];
strcpy(buffer,s.GetBuffer(0)); // copy the contents of CString into a char buffer
I don't know why you would want to put a string array into an int array -- they can easily be represented in a char array (see above). But, if you did do that, you can put them into a CString like this:
int array[] = {'H','e','l','l','o',0 };
CString string;
for (int i = 0; array[i] != 0; i++)
string += (char)array[i]; // notice you need to type cast from int to char
|
|
|
|
|
Hmm... Sorry for posting so much code, but I need to give you all an idea of what im doing
CString toASCII(CString input)
{
int i = 0;
int int_buffer;
int int_output;
char byte_buffer;
CString output;
while(i < input.GetLength())
{
byte_buffer = input.GetAt(i);
int_buffer = byte_buffer;
output += int_buffer;
i++;
}
return output;
}
-----
What I get out is what I put in. What im trying to do is get the ASCII number value out.
I know that my problem is probably on this line: output += int_buffer;
The CString is reconizing my int as a byte, instead of a number. How can i do
int a = 132;
CString str;
str = a;
and have str contain "123"? At least i think thats where my problem is, maybe it isn't.
Thanks for all the help.
|
|
|
|
|
CString has a GetBuffer function which gives you a char*. Call ReleaseBuffer when you're done with it.
You cannot use += on a class object, unless operator + is defined. The [] operator works in a CString though.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Thats odd, += works fine... it doesnt appear to be the problem, I input "hi" it returns "hi".
I want it to return "104105" (h-104 i-105)
|
|
|
|
|
Then you should use Left() and Mid()
It's odd to me that += works, but I admit I've never tried it.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Yes, += works just fine. I use it quite often.
|
|
|
|
|
Doh. It concatenates strings. My first reading of that code made me think he was trying to do pointer arithmetic with it.
Thanks.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
try this:
int x = 123;
CString s;
s.Format("%d", x);
// now s = "123" -- this a string representation of the integer.
|
|
|
|
|
One more question (thanks, you have all been very helpful so far).
How can i do:
int x;
CString str = "5";
x = str;
and have x = 5? Is there a function that can be used to convert to a int from a CString? I assume its probably similar to the CString.Format()?
Thanks!
|
|
|
|
|
int x = atoi(str.GetBuffer(0));
|
|
|
|
|
Try this.
int x;
CString str ="5";
x = _ttoi(str);
I think there is another function like that for Unicode also but off the top of my head I can't think of it.
Cheers
|
|
|
|
|
Read the VC forum FAQ which has an entry on converting numbers to their string representations.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Out of topic.
Interesting to see someone from C# coming to C++.
Job requirements make you do this, or our of shear interest?
|
|
|
|
|
Hi!
Does anybody know if there´s a specific message I can send (using SendMessage()) to an already open Windows file Open/Save dialog telling it to change path?
I know this can be done but I´m not sure that this metod it the right (best) one.
Thanks!
/Jonatan
|
|
|
|
|
I'm working on winsock application. The debug mode works fine but when I want to compile the release mode I got an error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup. I noticed the it can compile if I remove getaddrinfo, why?
Thanks!
|
|
|
|
|
Ehhh, I'm sorry but this "does not compute".
You say you get a linker error in Release mode, but then you say you can compile if removing the call(s) to getaddrinfo, implying you can't compile at all with that call in place. Odd.
I however suspect that you replaced "link" with "compile" in the last sentence.
From your error message it's clear that you are trying to create a console application. Is that correct? If so, somehow the (obviously) needed symbol main isn't defined for your Release mode build. Perhaps that can help you zoom in on the problem.
If not, a little more info might be helpful.
It could also be that you have mixed up your libraries or your libraries include paths, using older stuff for the Release build
|
|
|
|
|
Anyone know how to set a modeless dialog "active" on mouseover? (Kinda like x-windows)
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
Handle WM_MOUSEMOVE and make the dialog the active window (if it isn't already). You have to do more work if you also want to relinquish the "active" state when the mouse leaves the dialog. You could do this by calling TrackMouseEvent() and handling WM_MOUSELEAVE , but this only works on > Win95.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
"Handle WM_MOUSEMOVE and make the dialog the active window (if it isn't already)." <-- this is what i don't know how to do. What fcn call makes the dialog "active" as if I clicked on it??
thnx in advance!
~nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
Would you believe, SetActiveWindow() .
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Well, I guess it never hurts to first consider the obvious
thanx!
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
Suppose a TCP/IP server application is running on a Wndows 2000 machine. It listens on a certain port and various clients can connect via this port.
Now what is the limit of connections, this server can accept from clients by default in Win2k. (Assume there is no other load on server it just accepts connections).
Is there any way we can increase the number of sockets to be accepted in Win2k ???
PaunTM
|
|
|
|
|
The EULA forbids you to accept more than 10 incoming connections for a Workstation, so that would be the limit (at least it used to forbid you, but since they apparently change EULA's with even security patches nowadays it might be even worse). AFAIK this is an accumulated maximum for _all_ IP-based services/server-style-connections, basically making what used-to-be-known-as "NT Workstation" unusable for anything server-ish net-related.
The only (legal) way to increase this would be to cash up a lot of (I believe the technical term is "shitload") of money to get the Server (or DataCenter or whatever they call it this week), even that it technically is AFAIK exactly zero difference wrt the IP stack between the different versions.
Perhaps you could just try to connect with a bunch of clients and see what limit you get?
|
|
|
|
|
I think that 2k pro will accept unlimited connections (or to the limit of the hardware/software). BUT, lets say 11 connection attempts come in at once to this same box. One of them will be denied or blocked until the others are processed. This is one of the limits removed by a 'Server' version.
This simply limits the rate at which remote clients can connect. Further attempts bounce or block, but probably bounce (bouncing makes it unreliable as a server platform blocking merely slows it down.)
MS doesnt want to limit the total number of raw connections because some applications use multiple sockets in order do their thing. For instance, a P2P app may have many connections open.
cant remember where I read this, or if this is what I read.
|
|
|
|