include <iostream>
#include <string>
#include <vector>
#include <typeinfo>
using namespace std;
using namespace cv;
// leetcode
void split_(const string& s, vector<string>& tokens, char delim = ' ') {
tokens.clear();
auto string_find_first_not = [s, delim](size_t pos = 0) -> size_t {
for (size_t i = pos; i < s.size(); i++) {
if (s[i] != delim) return i;
}
return string::npos;
};
size_t lastPos = string_find_first_not(0);
size_t pos = s.find(delim, lastPos);
while (lastPos != string::npos) {
tokens.emplace_back(s.substr(lastPos, pos - lastPos));
lastPos = string_find_first_not(pos);
pos = s.find(delim, lastPos);
}
}
bool exist_file(const string &name){
ifstream f(name.c_str());
return f.good();
}
int main(void)
{
// 读取标签文件
// string const file = "123.txt";
// file
for(int i=0;i<200; i++){
string file_path;
file_path.append(path.c_str());
file_path.append("/");
file_path.append(to_string(i+1));
file_path.append(file_end.c_str());
bool file_flag;
// 读取文件
ifstream stream(file_path);
char buffer[256];
vector<string> position;
string img_path, line;
float cond;
int x1,y1,x2,y2;
// file_exist
file_flag = exist_file(file_path);
// get data
while(file_flag && !(stream.eof())){
stream.getline(buffer,256);
line = string(buffer);
if (line.length() > 0){ // have data
// 字符串分割
split_(line, position);
// label info
img_path = position[0];
cond = atof(position[1].c_str());
x1 = atoi(position[2].c_str());
y1 = atoi(position[3].c_str());
x2 = atoi(position[4].c_str());
y2 = atoi(position[5].c_str());
}
}
}
return 0;
}
|