有什么不对这个字符数组code? [英] What is wrong with this char array code?

查看:201
本文介绍了有什么不对这个字符数组code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C ++中,只有被编程几天让这看起来愚蠢的,但你可以发现为什么我的阵列无法正常工作?这是一个程序,我设计,将解决数独谜题的开始,但我使用来解决它不能正常工作的二维数组。

I'm new to C++, only been programming a few days so this might seem stupid, but can you spot why my arrays are not working correctly? This is the start of a program I'm designing that will solve Sudoku puzzles, but the 2D array that I'm using to solve it isn't working correctly.

#include <iostream>
#include <string>
using namespace std;

int main () {
    char dash[9][9];
    for (int array=0; array<9; array++) {
        for (int array2=0; array2<9; array2++) {
            dash[array][array2]=array2;
            cout << dash[array][array2];
        }
    }
    cout << dash[1][4] << endl; //This is temporary, but for some reason nothing outputs when I do this command.
    cout << "╔═══════════╦═══════════╦═══════════╗" << endl;
    for (int count=0; count<3; count++) {
        for (int count2=0; count2<3; count2++) {
            cout << "║_" << dash[count][count2*3] << "_|_" << dash[count]    [count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
        }
            cout << "║" << endl;
    }
    cout << "╠═══════════╬═══════════╬═══════════╣" << endl;
    for (int count=0; count<3; count++) {
        for (int count2=0; count2<3; count2++) {
            cout << "║_" << dash[count][count2*3] << "_|_" << dash[count]    [count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
        }
        cout << "║" << endl;
    }
cout << "╠═══════════╬═══════════╬═══════════╣" << endl;
for (int count=0; count<3; count++) {
    for (int count2=0; count2<3; count2++) {
        cout << "║_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
    }
    cout << "║" << endl;
}
cout << "╚═══════════╩═══════════╩═══════════╝" << endl;
return 0;

}

另外我知道,有可能是更容易的方法来构建独板,但我可以在我的脑海里已经看到了这一个会是如何工作的,如果失败,那么,唯一的学习方式是失败的。所有我想知道的是什么是错的数组。

Also I'm aware that there may be easier ways to build the Sudoku board, but I can already see in my mind how this one will work, and if it fails, well, the only way to learn is by failure. All I want to know is what is wrong with the arrays.

推荐答案

您正在尝试好像他们是整数,显示字符。那么,在技术上,他们,但他们不显示为整数。要么改变你的字符数组为int数组(很容易),或每次显示数据,将它转换为int(乏味)。

You're trying to display chars as if they were integers. Well, technically, they are, but they don't display as integers. Either change your char array to an int array(very easy), or every time you display the data, cast it to int(tedious).

这篇关于有什么不对这个字符数组code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆