string fnd = "dataset"; string rep = "labels"; string buf = "d:/data/dataset/ii.jpg"; buf = buf.replace(buf.find(fnd), fnd.length(), rep);
去掉由于window下引入的 '/r' 字符
fstream fp("val.txt"); vector<string> fn_vec; while(!fp.eof()){ string buf; getline(fp, buf); if(buf.empty()) continue; if (buf.find("\r") > 0) buf = buf.replace(buf.find("\r"), 1, ""); } fp.close();