How to print ascii values from 0 to 255 in C++ ? i have seen many programs regarding this but didnt understand them ...so plz give expalnation also.

This is the C forum so this is how you could do it in C

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i;
	for( i = 0; i < 256; i++ )
		printf("%c",i);
	return 0;
}

For C++ you could do this

#include <iostream>
using namespace std;

int main()
{
	for( int i = 0; i < 256; i++ )
		cout << char(i);

	return 0;
}

If you really need an explanation then maybe you should go look at http://www.asciitable.com/ since its pretty straight forward.

Not all the values between 0 and 255 have printable ascii values. The only printable ascii values are between 32 (a space) and 126 (the dash - ). All the values outside that range will just print nothing, squares, or other seemingly random garbage. See this ascii chart for all the values.

Thanx Sean and Melvin for solving my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.