c++ 文件流 ifstream 读取txt文件中数或者字符串


读取数

 ifstream infile;
    infile.open("/home/zss/Documents/ORB_SLAM2/0-612.txt");
    for (int i = 0; i < 7; i++)
    {
        for (int j = 0; j < 2207; j++)
        {
            yolo_detection[j].reserve(20);
            infile >>zss;
            yolo_detection[j].push_back(zss);
        }
    }
    infile.close();

读取字符串

ifstream infile3;
    infile3.open("/home/zss/Documents/ORB_SLAM2/label.txt");
    string jh;
    while(getline(infile3,jh))
    {
        label_name.push_back(jh);
    }
    infile3.close();

你可能感兴趣的:(c++)