letters

closed account (48CM4iN6)
hi . i'm having a project related to seat reservation system. can you guys help me out of the idea in generating letters? I dont know how to loop letters. This letters would be the designated seat number . Any help or idea would be really helpful.javascript:PostPreview()
Generating letters?
If you mean randomly generating letters between a-z you can just use the rand() function and assign the result to a char variable.
Take a look at this:
http://www.asciitable.com/
closed account (48CM4iN6)
The objective is to loop letters from a-z respectively , not just random letters.
1
2
3
4
for(char a = 'a'; a <= 'z'; ++a)
{
std::cout<<a;
}
> The objective is to loop letters from a-z respectively

The only portable way to do this is to create a sequence containing chars 'a' to 'z' and iterate through the sequence. For example:

1
2
3
4
5
6
7
static const char a_to_z[] = "abcdefghijklmnopqrstuvwxyz" ;

for( char ch : a_to_z ) 
{
    // use ch
    std::cout << ch ;  
} 

closed account (48CM4iN6)
thank you BlackSheep and JLBorges . I have succesfully done my objective
for( char ch : a_to_z )
is this even legal? can you give an explanation on the link?
closed account (48CM4iN6)
Black Sheep's answer satisfied my answer
> for( char ch : a_to_z )
> is this even legal?

Yes,.
Assuming that 'even legal' means 'in conformance with the IS for C++'.


> can you give an explanation on the link?

What on earth is an 'explanation on the link'?

Last edited on
I believe it's part of C++11 if you are lucky enough to have a compiler that supports it.
> if you are lucky enough to have a compiler that supports it.

There is no element of luck involved.
Anyone who wants it can get a compiler that supports range based loops - for free.
Last edited on
What on earth is an 'explanation on the link'?

sorry, probably i wrote it awkwardly, i mean a link that explain for syntax you just used. because it's not an ordinary for
> i mean a link that explain for syntax you just used.

Ah!

http://www2.research.att.com/~bs/C++0xFAQ.html#for

Current releases from GNU and clang, and the beta from Microsoft are conforming wrt this.

Topic archived. No new replies allowed.