Solved

ascii representation of number

Posted on 2001-08-15
4
301 Views
Last Modified: 2008-03-17
Hi.  Using Visual C++ Builder 5 how can I get the ASCII representation of a number.

I want to print the list of them in a RealEdit.  (I actually asked this question before, but had trouble changing the syntax from the given printf format to this one)

String char1;
for (int i=0; i < 255; i++) {
 Char1 = //help ?????????????
 RichEdit1->Lines->Add((String)i + " => " + char1);
}

Thanks for the help
0
Comment
Question by:Lmoen
4 Comments
 
LVL 2

Accepted Solution

by:
sateesh_babu earned 50 total points
ID: 6391586
This is a simple program that prints that ASCII representation of each of the codes

for (int i = 0; i < 255; i++)
{
    printf("%d\t%c\n", i, i);
}

Hope this helps!!!
Babu
0
 
LVL 1

Expert Comment

by:RideOn
ID: 6391661
hi Lmoen

if u use borland C++Builder (not Visual C++ Builder, that doesn't exist but there is Visual C++ from Microsoft) u can use the AnsiString Class.

Use this code lines:


String char1;
for (int i=0; i < 255; i++)
{
  char1 = AnsiString::StringOfChar(i, 1);
  ListBox1->Items->Add((String)i + " => " + char1);
}
0
 
LVL 30

Expert Comment

by:Axter
ID: 6392221
Here's a nice function to convert a number to a std::string

#include <sstream>
#include <string>

template <typename T>
std::string Ttos(T arg)
{
   std::ostringstream buffer;
   buffer << arg; // send to the ostringstream
   return buffer.str(); // capture the string
}

0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6392397
Will a "String" take an sprintf()?
If so, try this.

String char1;
for (int i=0; i < 255; i++)
   {
   sprintf(char1, "%d", i);
   RichEdit1->Lines->Add(char1);
   }

You may have to give it the address
   &char1
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

856 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