Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# How can i convert Ascii to CString

Posted on 2006-06-17
Medium Priority
1,542 Views
How can i convert Ascii (represented as UINT) to CString ?
0
Question by:netformx
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 3

LVL 12

Expert Comment

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

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

ID: 16928663
Is the solution working ?
0

LVL 12

Expert Comment

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

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

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

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

ID: 16928774
second solution worked :-)
0

## Featured Post

Question has a verified solution.

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

This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there isâ€¦
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a Gâ€¦
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relatâ€¦
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
###### Suggested Courses
Course of the Month7 days, 15 hours left to enroll