将数字和字符初始化为2D数组

时间:2015-10-06 04:14:51

标签: arrays numbers 2d character initializing

我必须实施一副带有数字和字母的卡片。这是我到目前为止所做的:

string deck [6][6] =
{
    {1A, 1B, 1C, 1D},
    {2A, 2B, 2C, 2D},
    {3A, 3B, 3C, 3D},
    {4A, 4B, 4C, 4D},
    {  ,   ,   ,   };

};
int main ()
{
   cout << deck[0][0] << endl;
}

我收到错误:

  

整数常量

上的无效后缀'A'

1 个答案:

答案 0 :(得分:0)

您收到此错误是因为您需要将字符串换成双引号。如果要使用静态初始化/声明,它应如下所示:

System/setProperty

您可以使用两个嵌套的std::string deck[4][4] = { { "1A", "1B", "1C", "1D"}, { "2A", "2B", "2C", "2D"}, { "3A", "3B", "3C", "3D"}, { "4A", "4B", "4C", "4D"} }; 循环显示卡组的全部内容:

for