when ever i try to initialize this array this way it gives an error
char alphabet[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'};
this is the error i get
error C2059: syntax error : '{'
Wy are you using type string? I would recommend to use type char[], however, both types works fine on my compiler. Try do compile this code:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <string>
std::string alphabet[26] //you can also use char, but then you have to
// change all the " into '
= { "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" };
int main()
{
std::cout<<alphabet[0];
return 0;
}
For your array, when you declare it with the values you want it to hold you don't need to declare the size of array; the computer counts the variables.
Changing your compiler isn't the answer to the problem.
I suggest (as has already been suggested) that you post the whole code as it stands, not bits and peices of it which could be taken out of context.
thats all my code for this class.
sorry its not indented and stuff
i dont know how to post it so it looks like code
any ideas as to why it i get the error: error C2059: syntax error : '{'
in regards to
string alphabet[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" };
Like i have told you before, the alpabet[26] don't cause an error when i use it. However, the syntax int var[x][y]={{...}{...}}
, as you use in the line after declaring alphabet, does cause an error when i try to compile it. It looks like the same error with another compiler: it says i cant use "{" (->the second "{") before "}" token. Could that be the problem?
Like i have told you before, the alpabet[26] don't cause an error when i use it. However, the syntax
int var[x][y]={{...}{...}}
, as you use in the line after declaring alphabet, does cause an error when i try to compile it. It looks like the same error with another compiler: it says i cant use "{" (->the second "{") before "}" token. Could that be the problem?
Try to use the #format if you use code in your message, thats easier to read.
I'm not very familiar with multideminsinal arrays. After trying i found the following code. This code does compile, and it works as it has to work.
However, i cant find the differnce between this and your first code... :)
1 2 3 4 5 6 7 8 9
#include <iostream>
int array[2][2]={{1,2},{3,4}};
int main()
{
std::cout<<array[0][0];
return 0;
}