파일의 맞춤법을 검사하는 libspellcheck 맞춤법 검사 라이브러리에 대한 함수를 만들고 있습니다. 함수는 텍스트 파일을 읽고 그 내용을 맞춤법 검사 기능으로 보냅니다. 맞춤법 검사 기능으로 텍스트를 올바르게 처리하려면 모든 줄 바꿈을 공백으로 바꿔야합니다. 나는 이것을 위해 부스트를 사용하기로 결정했다. 여기 내 기능은 다음과 같습니다.부스트 문자열 바꾸기가 줄 바꿈을 문자열로 바꾸지 않는다
spelling check_spelling_file(char *filename, char *dict, string sepChar)
{
string line;
string fileContents = "";
ifstream fileCheck (filename);
if (fileCheck.is_open())
{
while (fileCheck.good())
{
getline (fileCheck,line);
fileContents = fileContents + line;
}
fileCheck.close();
}
else
{
throw 1;
}
boost::replace_all(fileContents, "\r\n", " ");
boost::replace_all(fileContents, "\n", " ");
cout << fileContents;
spelling s;
s = check_spelling_string(dict, fileContents, sepChar);
return s;
}
라이브러리를 컴파일 한 후 샘플 파일을 사용하여 테스트 응용 프로그램을 만들었습니다.
테스트 응용 프로그램 코드 :
#include "spellcheck.h"
using namespace std;
int main(void)
{
spelling s;
s = check_spelling_file("test", "english.dict", "\n");
cout << "Misspelled words:" << endl << endl;
cout << s.badList;
cout << endl;
return 0;
}
테스트 파일 :
This is a tst of the new featurs in this library.
I wonder, iz this spelled correcty.
출력은 : 당신이 볼 수 있듯이
This is a tst of the new featurs in this library.I wonder, iz this spelled correcty.Misspelled words:
This
a
tst
featurs
libraryI
iz
correcty
의 줄 바꿈은 교체되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
아, 조크가 30 초 동안 너를 이길 ... –
퓨 리. 어쨌든 +1하십시오. – jrok