ogre에서 중국어 경로를 읽을 수 없는 해결 방법

1931 단어 중국어
다음은ogre의 파일 조작과 관련된 원본 코드입니다
코드
    DataStreamPtr FileSystemArchive::open(const String& filename) const

    {

        String full_path = concatenate_path(mName, filename);



        // Use filesystem to determine size 

        // (quicker than streaming to the end and back)

        struct stat tagStat;

    int ret = stat(full_path.c_str(), &tagStat);

        assert(ret == 0 && "Problem getting file size" ); 



        // Always open in binary mode

        std::ifstream *origStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)();

        origStream->open(full_path.c_str(), std::ios::in | std::ios::binary); 



        // Should check ensure open succeeded, in case fail for some reason.

        if (origStream->fail())

        {

            OGRE_DELETE_T(origStream, basic_ifstream, MEMCATEGORY_GENERAL);

            OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,

                "Cannot open file: " + filename,

                "FileSystemArchive::open");

        }



        /// Construct return stream, tell it to delete on destroy

        FileStreamDataStream* stream = OGRE_NEW FileStreamDataStream(filename,

            origStream, tagStat.st_size, true);

        return DataStreamPtr(stream);

    }


주요 코드는
origStream->open(full_path.c_str(), std::ios::in | std::ios::binary);




파일 흐름에서 파일을 열기 전에 언어 환경을 설정합니다
std::locale::global(std::locale(""));




다음에 우리는 중국어 경로의 문제가 해결되었지만 파일에 정형이나 부동점형 데이터를 쓸 때 문제가 있다는 것을 발견했다. 예를 들어'1000'이 출력된 후에'1000'이 되었다.
이것은 바로 우리가 언어 환경을 바꾸었기 때문이다. 수정을 최소화하기 위해서, 우리는 파일을 연 후에 이전의 설정을 복원해야 한다
std::locale saveLocal = std::locale::global(std::locale(""));

origStream->open(full_path.c_str(), std::ios::in | std::ios::binary);

std::locale::global(saveLocal);

좋은 웹페이지 즐겨찾기