0

I'm trying to input these letters into and array using the following an tex

[TEX]char Letters[26] ={"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
[/TEX]

my complier has an error reading
too many initializers

Please help

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Nick Evan
0

Get a better compiler. And post a real code example.

His compiler's fine.

You're really living up to your the interests you list in your profile tonight, aren't you?

1

If you're using chars, then use single quotes instead of double. Double quotes are for strings (more then 1 char).
So it would look like this:

char Letters[26] = {'a','b','c',    /*etc etc etc*/    };

But the easier way to do this, would be to initialize them as a string :

char Letters[] = "abcdefghijklmnopqrstuvwxyz";
    cout << "There are " << strlen(Letters) << " letters in the array";

output: There are 26 letters in the array Or you could use std::strings, because of the plain simplicity of it:

std::string Letters = "abcdefghijklmnopqrstuvwxyz";
cout << "There are " << Letters.size() << " letters in the array";
cout << "The first is " << Letters[0] << ", the last is " << Letters[Letters.size()-1];

output:

There are 26 letters in the array
The first is a, the last is z
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.