在经过一定数量的迭代后如何在输出文件中创建新行?

问题描述 投票:-2回答:1

我正在尝试将数组输出到.txt文件,并希望在80次迭代后创建新行。使用istream或ostream时我没有问题,但是该函数的逻辑很棘手。

std::ostream& operator<<(std::ostream& output, const MyClass& temp) {
    for (int i = 0; i < capacity; i++) {

        output << temp.myArray[i];
        if (i % 80 == 0){
          output<<\n;
        }
        return output;
    }
}
c++ ostream
1个回答
0
投票

我认为应该是

output<<'\n';
© www.soinside.com 2019 - 2024. All rights reserved.