Solved

How can i convert Ascii to CString

Posted on 2006-06-17
8
1,326 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now