c ++试图将字符串输入管道输入到2dmatrix

时间:2016-10-24 13:26:17

标签: c++ cin

我的源代码如下:

string** field = new string*[m]; //initialise a mxn Matrix=> field.
for (int i = 0; i < m; i++) { // we do this because the compiler does not know the ammount of memory required in advance hence use of poitners. 
    field[i] = new string[n]; 
}

for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
        cin >> &field[i][j];
    }
}

我在尝试将输入从cin推送到我的2d矩阵字段时遇到了麻烦。我试过双重解除引用即。和&amp;&amp;字段,但仍然得到相同的错误。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我最初写过cin&gt;&gt; field [i] [j]但是因为intellisense说没有运算符匹配std :: istream和std :: string类型的操作数而感到困惑。要解决这个问题我必须导入字符串更正后的代码如下:

    #include <string>;

//...
    string** field = new string*[m]; //initialise a mxn Matrix=> field.
    for (int i = 0; i < m; i++) { // we do this because the compiler does not know the ammount of memory required in advance hence use of poitners. 
        field[i] = new string[n]; 
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            cin >> field[i][j];
        }
    }