Solved

ascii representation of number

Posted on 2001-08-15
4
315 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
[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
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

624 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