C++向指定路径的文件中读写double数据

指定路径中创建名为0、1、2...的txt文件

并写入double类型数据

#include <iostream> 
#include<string.h>
#include <stdio.h>
#include <iomanip> 
#include<fstream>
int main()
{
    int num = 0;
    double row = 1231231230.1231313321;
    for(int p=0;p<2;++p)
    {
        // step 1 建立往里面填写的路径
        std::string path = "/home/datafile/";
        std::string store_path=path+std::to_string(num)+".txt";
        std::cout<< store_path <<std::endl;
        
        // step 2 确认路径正确后 往里面填写内容并保存
        //TODO 确认float的读写,并加入点云数据处理中
        std::ofstream ofile; 
        ofile.open(store_path,std::ios::app);//以追加模式打开文件
        std::cout.precision(22);
        std::cout.setf(std::ios::fixed);
        ofile<<num<<std::endl;
        ofile << std::setiosflags(std::ios::fixed) << std::setprecision(22) << row <<std::endl;//用正常方式写入double类型数据,而不用科学计数法;并指定写入数据的小数点精度
        ofile.close();
        num = num +1;

    }

}

猜你喜欢

转载自blog.csdn.net/qq_45068787/article/details/129009403