Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ascii representation of number

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
Suggested Courses

916 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