c++如何循环输入文本内容

问题遇到的现象和发生背景

c++如何循环输入文本内容

img


像这样每一行为一组数据,要通过循环对文本中每一组数据进行测试,for和while怎么实现啊

你是问循环输入文本内容吗,下面是一个实现,供参考:
C++写文件操作 - 黑马金牌编程 - 博客园
用C++产生随机数_Littlehero_121的博客-CSDN博客_c++生成1~100随机数
代码如下:

#include <iostream>
#include <fstream>   
#include <time.h>  //提供time函数原型 
#include <stdlib.h>  //提供srand和rand函数原型 
using namespace std;
int main(void){
    
    //https://www.cnblogs.com/hmjp/p/15888983.html
     ofstream ofs;
       //3.指定打开方式
    ofs.open("test.txt", ios::out);
    
    int i ,j;
    //https://blog.csdn.net/Littlehero_121/article/details/96994728
    srand((unsigned)time(NULL));//time()用系统时间初始化种。为rand()生成不同的随机种子。
    for(i=0;i<3;i++){
        for(j=0;j<9;j++){
            ofs<< rand() % 9+1<<" ";//生成1~9随机数,写入文件,也可自行选择要写入什么数 
        }
        ofs<<endl;
    }
    
    ofs.close();
    
    
    
    
    
    
}

img