내 코드에 약간의 문제가 있습니다. 내 코드는., : 및;을 제외한 모든 영숫자가 아닌 문자를 제거해야합니다. 새 줄에 점으로 끝나는 줄을 정렬합니다. 그래서, 같은 뭔가 :점으로 끝나는 줄 정렬 (.)
First, some characters, legal and illegal:)(=8skf-=&. This should be on a separate line. This too.
이 될 것입니다 :
First, some characters, legal and illegal: 8skf.
This should be on a separate line.
This too.
지금, 비 영숫자 스트립 코드의 첫 번째 부분은 완벽하게 작동합니다. 정렬 부분은 포인트까지 작동합니다. 그래서, 내 코드에서 위의 라인은 실제로이된다 :
First, some characters, legal and illegal: 8skf.
This should be on a separate line. This too.
나는이 새로운 라인이며, 내 코드는 새로운 라인이되는 과정에서 그것을 읽을 수 없기 때문에이 것을 이해합니다. 코드는 다음과 같습니다, 초기 파일을 읽고 불법 문자를 스트립, 임시 파일에 기록하는 함수를 호출하여
int writeFinalv(string path) {
readTempFiles(path.c_str());
string line;
string nline;
int start;
int lnth;
ifstream temp("temp.txt");
ofstream final;
int length;
final.open(path.c_str(), ios::out | ios::trunc);
if(temp.is_open()) {
while(getline(temp, line)) {
length = line.length();
for(int i = 0; i < length; i++) {
if(line[i] == '.') {
if(line[i+1] == ' ') {
nline = line.substr(0, (i+2));
}
else {
nline = line.substr(0, (i+1));
}
final << nline << "\n";
start = line.find(nline);
lnth = nline.length();
line.erase(start, lnth);
}
}
}
}
else {
error = true;
}
return 0;
}
내 코드 첫 번째 작품. 그런 다음, 임시 파일을 읽고, 점을 찾고 새 파일을 잘라내서 초기 파일에 씁니다. 미리 감사드립니다.
정확한 질문은 무엇입니까? –