메모장과 같은 프로그램을 만들고 있습니다. 내가 MZ하지만 메모장은 전체 EXE를 읽어 후 정지 EXE 파일에로드하는 경우 파일에서 텍스트를 얻으려면 나는 그러나ifstream을 끝까지 읽지 않는 이유는 무엇입니까?
while (!file.EOF())
{
mystr += file.get();
}
를 수행하여 버퍼에 각 문자를 읽어 보시기 바랍니다. ifstream을 바이너리 모드로 설정했지만 여전히 운이 없다. 내가 도대체 뭘 잘못하고있는 겁니까? 감사
코드 : 내가 EXE에로드하는 경우 (지저분한)
void LoadTextFromString(HWND ctrl, char* dirtypath, bool noquotes)
{
char *FileBuffer;
char *buf;
int count;
count = 0;
bool hasDot = false;
vector<int> quotes;
vector<string> files;
string temp;
if (noquotes)
{
goto noqu;
}
while(dirtypath[count] != 0)
{
if (dirtypath[count] == 34)
{
quotes.push_back(count);
}
count +=1;
}
if (quotes.size() < 3 || quotes.size() % 2 != 0)
{
return;
}
for (int i = 0; i < quotes.size(); i += 2)
{
temp = "";
for (int j = quotes[i] + 1; j < quotes[i + 1]; ++ j)
{
temp += dirtypath[j];
}
files.push_back(temp);
}
for(int i = 0; i < files.size(); ++i)
{
noqu:
if (!noquotes)
{
FileBuffer = (char*)files[i].c_str();
}
else
{
FileBuffer = dirtypath;
}
ifstream *tf;
tf = new ifstream(FileBuffer,ios::binary);
ifstream *file;
file = new ifstream(FileBuffer,ios::binary);
if(file->fail())
{
return;
}
int thelength;
thelength = 0;
while (!tf->eof())
{
if (tf->get() == 10)
{
thelength +=1;
}
thelength +=1;
}
tf->close();
if(thelength == 0)
{
SetWindowTextA(ctrl,"");
return;
}
buf = new char[thelength + 1];
int lenn;
lenn = 0;
char cr ;
cr = 10;
char tmp;
while (!file->eof())
{
buf[lenn] = file->get();
if (buf[lenn] == cr)
{
tmp = 13;
buf[lenn] = tmp;
buf[lenn + 1] = cr;
lenn += 1;
}
lenn += 1;
}
buf[lenn - 1] = 0;
file->read(buf,lenn);
SetWindowTextA(ctrl,buf);
file->close();
}
delete(buf);
}
MZ 란 무엇인가요? 끝까지 읽지 않는다는 것을 어떻게 알 수 있습니까? – WhirlWind
잘 MZ는 PE exe 헤더의 acii 버전입니다. 그러나 이것을 넘어서 읽지 않습니다 (IE의 줄 끝으로 보입니다). – jmasterx
파일을 여는 데 사용한 코드를 보여주십시오. 또한 isftream에는'EOF'가 아니라'eof'가 있습니다. 이것은 오타입니까? 아니면 다른 곳에서 진행되고 있습니까? –