该数组存储错误的数据 [英] The array is storing the wrong data

查看:89
本文介绍了该数组存储错误的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,

我试图使用 ExcelFormat填充excel单元格的数组图书馆 [ ^ ]

hey guys,
im trying to fill an array with excel cells using the ExcelFormat Library[^]

    cout << "read " << from << endl;
BasicExcel xls(from);
XLSFormatManager fmt_mgr(xls);
BasicExcelWorksheet* sheet = xls.GetWorksheet(0);
CellFormat fmt_general(fmt_mgr);
fmt_general.set_format_string("0.000");
const int fil = sheet->GetTotalCols();// n fil
const int col = sheet->GetTotalRows();//m col
for (int y = 0; y < col; ++y) {
    for (int x = 0; x < fil; ++x) {
        BasicExcelCell* cell = sheet->Cell(y, x);
        //cout << *store << "\t";
    }
}
for (int i = 0; i < col; i++)
{
    for (int j = 0; j < fil; j++)
    {
        if (sheet->Cell(i, j)->Type() == 2)
        {
             store[i*n + j] = sheet->Cell(i, j)->GetDouble();
        }
        else {
            store[i*n + j] = 0;
        }
        cout <<  i  << "/" << j <<"/" <<store[i*n + j] << "\t";
    }
    cout << "\n";
}





此代码使用excel数据填充数组,当我在控制台上查看存储内容时结果就是我所期待的。但是当我尝试稍后在我的代码上重新加载数组时,数据全部搞砸了显示除了首先存储的内容之外的任何内容。



即使我调用一个简单的循环来查看控制台中存储的数据都搞砸了



提前感谢



我尝试过:



我在上面的代码中循环完成数组的内容之后,我已经尝试过了,但是数据没有什么相似之处,除了两列应该是这样的。然后它开始存储两列的相同数据而不是其他所有内容。



this code fills the array with the excel data and when i look on console what is storing the result is what i'm expecting. but when I try to reload the array later on my code the data is all messed up showing anything but what it was stored in the first place.

even if I call a simple loop to see in console what is stored the data is all messed up

thanks in advance

What I have tried:

I've tried veryfing after the loop in the code above finish the contents of the array but the data is nothing similar, except for two columns that are as they should be.then it starts storing the same data of the two columns instead of everything else.

推荐答案

显然,你自己的代码对你来说就像一个黑盒子。它不符合你的期望,你不明白为什么。

以下内容不是直接解决你的问题,而是一个能帮助你自己理解错误的关键。

调试器是你的朋友。它将向您显示您的代码实际正在做什么。

按照执行,检查变量,您将看到有一个点,它停止做您期望的。

掌握Visual Studio 2010中的调试 - 初学者指南 [< a href =http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-A-Beginntarget =_ blanktitle =New Window> ^ ]

调试器 - 维基百科,免费的百科全书 [ ^ ]



你在哪里定义 store 以及 n的价值
Obviously, your own code is like a blackbox to you. It don't do what you expect, and you don't understand why.
What follow is not directly a solution to your problem, but a key that will help you to understand by yourself what is wrong.
The debugger is your friend. It will show you what your code is really doing.
Follow the execution, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Debugger - Wikipedia, the free encyclopedia[^]

Where do you define store and what is the value of n


这篇关于该数组存储错误的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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