<i id='69QCl'><tr id='69QCl'><dt id='69QCl'><q id='69QCl'><span id='69QCl'><b id='69QCl'><form id='69QCl'><ins id='69QCl'></ins><ul id='69QCl'></ul><sub id='69QCl'></sub></form><legend id='69QCl'></legend><bdo id='69QCl'><pre id='69QCl'><center id='69QCl'></center></pre></bdo></b><th id='69QCl'></th></span></q></dt></tr></i><div id='69QCl'><tfoot id='69QCl'></tfoot><dl id='69QCl'><fieldset id='69QCl'></fieldset></dl></div>
  1. <small id='69QCl'></small><noframes id='69QCl'>

    1. <legend id='69QCl'><style id='69QCl'><dir id='69QCl'><q id='69QCl'></q></dir></style></legend>
        <bdo id='69QCl'></bdo><ul id='69QCl'></ul>
    2. <tfoot id='69QCl'></tfoot>
    3. 从 .txt 文件读取到 C++ 中的二维数组

      时间:2023-10-08
      <tfoot id='OdHdp'></tfoot>
        <bdo id='OdHdp'></bdo><ul id='OdHdp'></ul>
        • <small id='OdHdp'></small><noframes id='OdHdp'>

          <i id='OdHdp'><tr id='OdHdp'><dt id='OdHdp'><q id='OdHdp'><span id='OdHdp'><b id='OdHdp'><form id='OdHdp'><ins id='OdHdp'></ins><ul id='OdHdp'></ul><sub id='OdHdp'></sub></form><legend id='OdHdp'></legend><bdo id='OdHdp'><pre id='OdHdp'><center id='OdHdp'></center></pre></bdo></b><th id='OdHdp'></th></span></q></dt></tr></i><div id='OdHdp'><tfoot id='OdHdp'></tfoot><dl id='OdHdp'><fieldset id='OdHdp'></fieldset></dl></div>

              <tbody id='OdHdp'></tbody>

          1. <legend id='OdHdp'><style id='OdHdp'><dir id='OdHdp'><q id='OdHdp'></q></dir></style></legend>
                本文介绍了从 .txt 文件读取到 C++ 中的二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                所以要么我是个彻头彻尾的白痴,这正直盯着我看,但我似乎无法在谷歌或这里找到任何我能理解的资源.

                So either I'm a complete idiot and this is staring me right in the face, but I just can't seem to find any resources I can understand on google, or here.

                我有一个包含多行整数的文本文件,每个整数用空格分隔,我想将这些整数读入一个数组,其中每一行是数组的第一维,每个整数在那条线上被保​​存到第二维中.

                I've got a text file which contains several lines of integers, each integer is separated by a space, I want to read these integers into an array, where each new line is the first dimension of the array, and every integer on that line is saved into the second dimension.

                可能用了最糟糕的术语来解释,抱歉.

                Probably used the worst terminology to explain that, sorry.

                我的文本文件如下所示:

                My text file looks something like this:

                100 200 300 400 500
                101 202 303 404 505
                111 222 333 444 555
                

                我希望得到的数组是这样的:

                And I want the resulting array to be something like this:

                int myArray[3][5] = {{100, 200, 300, 400, 500},
                                     {101, 202, 303, 404, 505},
                                     {111, 222, 333, 444, 555}};
                

                推荐答案

                我相信

                istream inputStream;
                int myArray[3][5];
                for(int i = 0; i < 3; i++)
                    for(int j = 0; j < 5; j++)
                        istream >> myArray[i][j];
                

                应该做你需要的.

                这篇关于从 .txt 文件读取到 C++ 中的二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 C++ 中模拟按键按下 下一篇:在 C++ 中读取格式化输入的最简单方法?

                相关文章

                最新文章

                  <i id='B72cg'><tr id='B72cg'><dt id='B72cg'><q id='B72cg'><span id='B72cg'><b id='B72cg'><form id='B72cg'><ins id='B72cg'></ins><ul id='B72cg'></ul><sub id='B72cg'></sub></form><legend id='B72cg'></legend><bdo id='B72cg'><pre id='B72cg'><center id='B72cg'></center></pre></bdo></b><th id='B72cg'></th></span></q></dt></tr></i><div id='B72cg'><tfoot id='B72cg'></tfoot><dl id='B72cg'><fieldset id='B72cg'></fieldset></dl></div>
                  1. <tfoot id='B72cg'></tfoot>
                  2. <small id='B72cg'></small><noframes id='B72cg'>

                  3. <legend id='B72cg'><style id='B72cg'><dir id='B72cg'><q id='B72cg'></q></dir></style></legend>
                      <bdo id='B72cg'></bdo><ul id='B72cg'></ul>