// Array for one's place
char arrayOnes[10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}

In the code above I'm having trouble declaring this array. I either get > error: too many initializers for ‘char [10]’

Recommended Answers

All 2 Replies

You are trying to initialize a 2d array when you onlty declared a 1d array. You can change it to

char arrayOnes[][10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}

If you can use strings I would suggest doing this

std::string arrayOnes[10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}

The type char arrayOnes[10]; is an array of 10 characters. In your initializer, you are defining an array of strings (which are themselves arrays of characters). This would be the correct version:

const char* arrayOnes[10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

The above defines an array of pointers to const-characters. A pointer to a const-character is the type of string literals like "one".

Of course, in more modern C++, we don't really use those kinds of C-style arrays anymore. In C++11, you would do this:

std::vector< std::string > arrayOnes = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
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.