letters

Mar 4, 2012 at 5:51am
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()
Mar 4, 2012 at 8:20am
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/
Mar 5, 2012 at 1:03pm
closed account (48CM4iN6)
The objective is to loop letters from a-z respectively , not just random letters.
Mar 5, 2012 at 2:02pm
1
2
3
4
for(char a = 'a'; a <= 'z'; ++a)
{
std::cout<<a;
}
Mar 5, 2012 at 2:39pm
> 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 ;  
} 

Mar 8, 2012 at 12:12pm
closed account (48CM4iN6)
thank you BlackSheep and JLBorges . I have succesfully done my objective
Mar 8, 2012 at 1:49pm
for( char ch : a_to_z )
is this even legal? can you give an explanation on the link?
Mar 8, 2012 at 3:03pm
closed account (48CM4iN6)
Black Sheep's answer satisfied my answer
Mar 8, 2012 at 6:00pm
> 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 Mar 8, 2012 at 6:02pm
Mar 8, 2012 at 6:07pm
I believe it's part of C++11 if you are lucky enough to have a compiler that supports it.
Mar 9, 2012 at 2:15am
> 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 Mar 9, 2012 at 3:30am
Mar 10, 2012 at 4:54pm
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
Mar 11, 2012 at 3:25am
> 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.