Solved

ascii representation of number

Posted on 2001-08-15
4
272 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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.

706 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

18 Experts available now in Live!

Get 1:1 Help Now