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

x
?
Solved

ascii representation of number

Posted on 2001-08-15
4
Medium Priority
?
320 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 150 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

664 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