打印2D std :: string数组

Wil*_*iam 6 c++

我试图用c ++初始化一个tic-tac-toe板,但输出总是给我六进制值.有没有办法将它们转换为实际的字符串值?

#include <iostream>
#include<string>

using namespace std;

int main()
{
    string tab[5][5] = { "1","|","2","|","3",
                         "-","+","-","+","-",
                         "4","|","5","|","6",
                         "-","+","-","+","-",
                         "7","|","8","|","9" };

    for(int i = 0; i <= 24; i++)
    {
        cout << tab[i] << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

Tan*_*ash 4

tab[i]您将发送to的值cout,因此您将获得内存地址。

您可能希望将项目嵌套得更深,例如tab[i][j].