C++,C#,输入输出流汇总(持续更新)

C++,C#,输入输出流汇总(持续更新)

C++输出

1.定义一个输出三重向量的函数。

void output_3Dvector(string path, vector<vector<vector<double>>> vec)
{
        ofstream outfile3D(path);
    outfile3D<<vec.size()<<vec.at(0).size()<<vec.at(0).at(0).size()<<endl;
    for(size_t i=0;i<vec.size();i++){
        for(size_t j=0;j<vec.at(i).size();j++){
            for (size_t k=0;k<vec.at(i).at(j).size();k++) {
                outfile3D <<  vec.at(i).at(k).at(0)<< "," << vec.at(i).at(k).at(1) << "," << vec.at(i).at(k).at(2) << "," <<vec.at(i).at(k).at(3) << " ," <<vec.at(i).at(k).at(4) << "," <<vec.at(i).at(k).at(5) << endl;//Dlib点深度数据X,Y,Z
            }
        }
    }
    outfile3D.close();
}

C++输入流

ifstream infile;//定义读取文件流,相对于程序来说是in
infile.open(txt);//打开文件
string line;
vector<double> vector0;
vector0.resize(3);
if (infile.eof())
{
    infile.close();
    cout<<"error open"<<endl;
}
if  (getline(infile, line)) {
    istringstream sin(line);
    std::vector<string> fields;
    string field;
    while (getline(sin, field, '\t')) {
    fields.push_back(field);
    }
    vector0.at(0)=atof(fields.at(1).data());
    vector0.at(1)=atof(fields.at(2).data());
    vector0.at(2)=atof(fields.at(3).data());
}
infile.close();

猜你喜欢

转载自blog.csdn.net/DexiangPeng/article/details/114681549

相关文章