Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cmd窗口停止工作,fstream读取的文本文件错误_C++_Arrays_Fstream - Fatal编程技术网

C++ cmd窗口停止工作,fstream读取的文本文件错误

C++ cmd窗口停止工作,fstream读取的文本文件错误,c++,arrays,fstream,C++,Arrays,Fstream,在函数Read()中,当我输出数组klas[]和nauj[]时,所有内容看起来都读取得很好,但在主函数中,它们被破坏了,似乎被其他文本文件填充。你知道这里有什么问题吗 #include <iostream> #include <fstream> using namespace std; const char klase[] = "klase.txt"; const char naujokai[] = "lele.txt"; void Read(int klas[],

在函数Read()中,当我输出数组klas[]和nauj[]时,所有内容看起来都读取得很好,但在主函数中,它们被破坏了,似乎被其他文本文件填充。你知道这里有什么问题吗

#include <iostream>
#include <fstream>

using namespace std;

const char klase[] = "klase.txt";
const char naujokai[] = "lele.txt";

void Read(int klas[], int nauj[], int &nk, int &nj);

int main()
{
    int klas[] = {};
    int nauj[] = {};
    int nk;
    int nj;
    Read(klas, nauj, nk, nj);

    for(int i = 0; i < nk; i++){
        cout << klas[i] << endl;
    }for(int i = 0; i < nj; i++){
        cout << nauj[i] << endl;
    }



    return 0;
}

void Read(int klas[], int nauj[], int &nk, int &nj)
{
    ifstream fklase(klase);
    fklase >> nk;
    for(int i = 0;i < nk;i++){
        fklase >> klas[i];
        cout << klas[i] << endl << endl;
    }
    fklase.close();
    ifstream fnaujokai(naujokai);
    fnaujokai >> nj;
    for(int i = 0; i < nj; i++){
        fnaujokai >> nauj[i];
        cout << nauj[i] << endl << endl;
    }
    fnaujokai.close();

}
#包括
#包括
使用名称空间std;
const char klase[]=“klase.txt”;
const char naujokai[]=“lele.txt”;
无效读取(内塔克拉斯[]、内塔诺伊[]、内塔诺伊和内塔诺伊、内塔诺伊和内塔诺伊);
int main()
{
int-klas[]={};
int nauj[]={};
int nk;
国际新泽西州;
Read(克拉斯群岛、瑙伊岛、北卡罗来纳州、新泽西州);
对于(int i=0;inauj[i];

cout零大小数组,如
int-klas[]={};
不是标准的,并且像在
fklase>>klas[i]中那样写入它们;
是未定义的行为,因为它们没有空间存储任何内容。另外请注意,当您使用
int-klas[]
作为一个函数参数,它实际上相当于
int*klas

零大小数组,例如
int-klas[]={};
不是标准的,并且像在
fklase>>klas[i]中那样写入它们;
是未定义的行为,因为它们没有空间存储任何东西。还要注意,当使用
int-klas[]
作为一个函数参数,它实际上相当于
int*klas

嗨,我更改了两个数组,使它们有一个像int-klas[100]这样的最大值,并且可以工作!谢谢!嗨,我更改了两个数组,使它们有一个像int-klas[100]这样的最大值,并且可以工作!谢谢!