too many initializers error

I'm getting s error: too many initializers for 'const wchar_t [3]'. What's wrong?

1
2
3
  void usernamearray(){
const wchar_t names [1][3] ={{"0x56","0x45","0x52"}};
cout << names[1][2]<<endl;
each of those strings has to be a single character

const wchar_t names [1][3] = { {'a', 'b', 'c'} };
Last edited on
Like rish1 said, each of those has to have a single character, such as 'a', not "aa".

You could use the library string with vectors

example:

1
2
3
4
5
6
7
8
        #include <iostream>
	#include <string>
	#include <vector>

	void usernamearray(){
		const vector<string> names [3] = {"0x56","0x45","0x52"};
		cout << names[1][2]<<endl;
	}
1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    const wchar_t names[1][3] = { { '\x56', '\x45', '\x52' } };
 
    for (unsigned i = 0; i < 3; ++i)
        std::wcout << names[0][i] << '\n';    // names[1][2] is outside the bounds of the array.
}


http://ideone.com/kjnTgA
Great thank you!
Topic archived. No new replies allowed.