小编Nic*_*ick的帖子

如何在C++中打印2D数组?

我试图使用数组在屏幕上打印文本文件,但我不确定为什么它不会出现在文本文件中.

文本文件:

1 2 3 4
5 6 7 8
Run Code Online (Sandbox Code Playgroud)

应用丢弃功能后,屏幕显示如下:

1
2
3
4
5
6
7
8
Run Code Online (Sandbox Code Playgroud)

代码:

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>

using namespace std;

const int MAX_SIZE = 20;
const int TOTAL_AID = 4;

void discard_line(ifstream &in);
void print(int print[][4] , int size);

int main()
{
    //string evnt_id[MAX_SIZE]; //stores event id
    int athlete_id[MAX_SIZE][TOTAL_AID]; //stores columns for athelete id
    int total_records;
    char c; 
    ifstream reg;
    reg.open("C:\\result.txt");

    discard_line(reg);
    total_records = 0;

    while( !reg.eof() )
    { …
Run Code Online (Sandbox Code Playgroud)

c++ arrays revision multidimensional-array

6
推荐指数
1
解决办法
6万
查看次数

标签 统计

arrays ×1

c++ ×1

multidimensional-array ×1

revision ×1