Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can i convert Ascii to CString

Posted on 2006-06-17
8
Medium Priority
?
1,580 Views
Last Modified: 2012-08-13
How can i convert Ascii (represented as UINT) to CString ?
0
Comment
Question by:netformx
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16928637
>> Ascii (represented as UINT)
By the way ASCII is represtented as char.
Then also it will like this

unsigned int c = 'a';
CString str;
str += c;

If you find it is char the simply replace
unsigned int c = 'a';
with
unsigned int c = 'a';
0
 

Author Comment

by:netformx
ID: 16928654
in this case the method parameter is UINT nChar, this nChar value is 103 (for 'g') and not 'g' itself.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16928663
Is the solution working ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16928670
>> in this case the method parameter is UINT nChar, this nChar value is 103 (for 'g') and not 'g' itself.
for a 4 byte UINT. Only the last byte is used if you are storing char.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16928677
Let me take your case then
UNIT c = 'g';
...


CString str;
str = c;  // c will be converted to char, and then assigned to str.
 
0
 

Author Comment

by:netformx
ID: 16928688
hi rageev,

when compiling this code:
UINT nChar = 103;
CString str = nChar;

i get an error (on the line -> CString str = nChar;)
 : error C2440: 'initializing' : cannot convert from 'UINT' to 'ATL::CStringT<BaseType,StringTraits>'

i'm working with visual studio 2005
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 2000 total points
ID: 16928698
Try this way
UNIT c = 'g';
CString str(c);

If it does not work then try this
UNIT c = 'g';
CString str((char)c); // explicitly typecase UINNT to char.
0
 

Author Comment

by:netformx
ID: 16928774
second solution worked :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question