.log 파일에서 텍스트를 읽으려고합니다. 원래는 Windows 콘솔 응용 프로그램을 사용하고 있지만 이제는 MFC를 사용하여 GUI 버전을 만들려고합니다. 내가 동안으로 while 루프를 설정할 때 문제가 (file.good는()), 완전히 루프를 건너 뛰고 잘 모르겠어요 왜 file.open()에 오류가 없기 때문에파일에서 읽을 수 없습니다.
void Conversion::toXml(CString openPath, CString savePath)
{
CString null("/0");
int c = openPath.GetLength(),q=0;
while(q<c)
{
if(openPath[q] == '\\')
{
openPath.Insert(q,'\\');
q++;
}
q++;
}
CStringA charstr(openPath);
const char* oPath((const char *) charstr);
CStringA charstr2(savePath);
const char* sPath((const char *) charstr2);
ifstream openFile;
ofstream savedFile(sPath);
string recText = "";
string temp;
openFile.open(oPath);
while(openFile.good())
{
getline(openFile,temp);
recText = recText + temp;
}
작은 버전 경로에 불필요한 백 슬래시를 추가,
#include <iostream>
#include <fstream>
#include <string>
#include "stdio.h"
#include <windows.h>
#include <algorithm>
#include <atlstr.h>
using namespace std;
int main()
{
string recText = "";
string temp;
CString path = "C:\\Users\\name\\Desktop\\2012-08-281.log";
CStringA charstr(path);
const char* oPath((const char *) charstr);
ifstream xmlDoc (oPath);
ofstream finished ("C:\\Users\\name\\Documents\\example3.xml");
while(xmlDoc.good())
{
getline(xmlDoc,temp);
recText = recText + temp;
}
finished<<recText<<endl;
return 0;
}
'null'문자열은 '/', ''0 '및' '\ 0' '의 세 문자를 포함하는 문자열입니다. 그게 그렇게되어 있니? –
@JoachimPileborg : 문제가되지 않습니다. 문자열은 사용되지 않습니다. – wallyk
파일 이름 구성이 잘못된 파일 이름을 생성하므로 결과적으로 해당 파일 이름이 열리지 않습니다. 파일이'.good()'이 아닙니다. – WhozCraig