키를 사용하여 외부 파일에서 짧은 바이너리를 읽고 싶었습니다.
3 A 0100 3 E 0101 3 G 0110 3 M 0111 3 N 1010 3 H 1011 2 S 100 1 T 00 2 10 2 I 111
3은 pos라는 정수에 있습니다.
A는 al이라는 문자에 있습니다.
0100은 bin 등이라는 배열에 있습니다.
파일을 열고 파일 데이터를 한 줄씩 읽고 필요한 것을 줄에서 추출하십시오.
std::string line;
ifstream read;
//open data files
read.open(file_name);
if(read.is_open())
cout << "File ./" << file_name << " is open.\n";
else {
cout << "Error opening " << file_name << ".\n";
exit(0);
}
while (std::getline(read, line))
{
// line =3 A 0100 3 E 0101 3 G 0110 3 ...
std::istringstream iss (std::move(line));
std::string val_str, al, bin;
while(! iss.str().empty())
{
try{
iss>>val_str;
int val= std::stoi(val_str); //val = 3 in the first run of the while loop
iss >> al; //al = A in the first run of the while loop
iss >> bin
// you can use val, al ,bin
}catch(..){
break;
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다