함수가 int reverse (ifstream & inFile, int 수준) 함수가 있습니다. 특정 분리 문자에 도달 할 때까지 한 번에 한 문자 씩 읽어야합니다. 그런 다음 해당 문자를 역순으로 표시합니다. 구분 기호는 호출 함수로 리턴됩니다. 구분 기호는 반대로 표시되지 않습니다.재귀 메서드를 사용하여 ifstream 입력을 역순으로 처리하십시오.
#include <fstream>
#include <cctype>
#include <iostream>
using namespace std;
inline bool checkSeparator(int someValue)
{
return(isspace(someValue) || someValue == (int)',' || someValue == (int)':' || someValue == (int)';' ||
someValue == (int)'.' || someValue == (int)'?' || someValue == (int)'!' || someValue == EOF);
}
int Reverse(ifstream &inFile, int level)
{
int input = inFile.get();
if (!checkSeparator(input))
Reverse(inFile, ++level);
--level;
if (level == 1)
input = toupper(input);
if (!checkSeparator(input))
cout.put(input);
if (checkSeparator(input))
return(input);
}
필자는 분리 기호를 실제로 반환 할 수 없었습니다. 모든 제어 경로가 값을 반환하지 않는 것 같습니다. 함수가 올바른 값을 반환하도록하려면 어떻게합니까? 감사.
코드에서 반환 값을 사용하지 않고 대신 void가 될 수 있습니까? – doctorlove