0

I just started with the class vector, but it didn't go so well. :(

I tried this:

void Initialize()
{
	int amount_of_char = 62;

	vector<char> char_table;
	for (int i = 97; i < 122+1; i++)	// 97 -> 'a', 122 -> 'z'
		char_table[i] = char(i);
	for (int i = 65; i < 90+1; i++)	// 65 -> 'A', 90 -> 'Z'
		char_table[i] = char(i);
	for (int i = 48; i < 57+1; i++)	// 48 -> '0', 57 -> '9'
		char_table[i] = char(i);

	for (int i = 0; i < int(char_table.size()); i++)
		std::cout << char_table[i];
}

It compiles without errors, but I get an Assertion error when I run the program: "Vector subscript out of range".

What is that?
I tried other ctors, like:

vector<char> char_table(100);

But it does not work.

Please Help

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by C++ Obliviator
0

You need to pre-initialize your array as you have gaps that aren't set with valid values! {0...47}, {58...64}, {91...96}

This question has already been answered. 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.