C++ 使用 fscanf 命令循环读取 TXT每行的数值数据(不用数组)

    // 设定导入的卫星角速度和角加速度数据
    char parasfileomega[100];
    int flag = 1;
    printf("是否导入默认的卫星仿真角速度及角加速度参数文件?(1:Yes/0:No)\n");
    cin >> flag;
    if (flag == 1) {
        strcpy_s(parasfileomega, "Test8192.txt");
    }
    if (!flag) {
        printf("请输入卫星仿真角速度和角加速度参数文件的完整路径(使用双斜杠):\n");
        cin >> parasfileomega;
    }
 

cout << "开始循环计算..." << endl;
    double t = 0.0;
    double pomegax=1, pomegay=1, pomegaz=1, pangaccx=1, pangaccy=1, pangaccz=1;
    
    FILE  *loadOmegaxyz;
    loadOmegaxyz = fopen(parasfileomega, "r");

    cout << "循环之前"<<pomegax << "  " << pomegay << "  " << pomegaz << endl;

for (int i = 0; i < rounds; i++)
    {
        
            t = t + i * step;
             
           
            fscanf(loadOmegaxyz, "%lf%lf%lf%lf%lf%lf\n", &pomegax, &pomegay, &pomegaz, &pangaccx, &pangaccy, &pangaccz);
            cout << "循环内部"<<pomegax << "  " << pomegay << "  " << pomegaz << endl;
            
            omega = Vector(pomegax, pomegay, pomegaz);//读取输入的参数;
            angacc = Vector(pangaccx, pangaccy, pangaccz);//读取输入的参数;

            
      
    }
  

    fclose(loadOmegaxyz);
    cout <<"出了循环"<< pomegax << "  "<< pomegay<<"  " << pomegaz << endl;


    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40993412/article/details/82662644