BasicExcel另存为中文文件名出错的解决

来源:互联网 发布:2017网络十大英语热词 编辑:程序博客网 时间:2024/06/07 13:29

wcstombs使用需要设置中文环境,具体修改代码如下:

bool Block::Create(const wchar_t* filename)// PURPOSE: Create a new block file and open it.// PURPOSE: If file is present, truncate it and then open it.// PROMISE: Return true if file is successfully created and opened, false if otherwise.{// Create new filesize_t filenameLength = 2*wcslen(filename)+1;char* name = new char[filenameLength];size_t converted = 0;wcstombs_s(&converted, name, filenameLength, filename, _TRUNCATE);//name[filenameLength] = 0;setlocale(LC_ALL,"");file_.open(name, ios_base::out | ios_base::trunc);setlocale(LC_ALL,"C");file_.close();file_.clear();// Open the filebool ret = this->Open(filename);delete[] name;return ret;}bool Block::Open(const wchar_t* filename, ios_base::openmode mode)// PURPOSE: Open an existing block file.// PROMISE: Return true if file is successfully opened, false if otherwise.{// Open existing file for reading or writing or bothsize_t filenameLength = wcslen(filename);filename_.resize(2*filenameLength+1, 0);setlocale(LC_ALL,"");wcstombs(&*(filename_.begin()), filename, 2*filenameLength+1);file_.open(&*(filename_.begin()), mode | ios_base::binary);setlocale(LC_ALL,"C");if (!file_.is_open()) return false;mode_ = mode;// Calculate filesizeif (mode & ios_base::in){file_.seekg(0, ios_base::end);fileSize_ = file_.tellg();}else if (mode & ios_base::out){file_.seekp(0, ios_base::end);fileSize_ = file_.tellp();}else{this->Close();return false;}// Calculate last index + 1indexEnd_ = fileSize_/blockSize_ + (fileSize_ % blockSize_ ? 1 : 0);return true;}


0 0
原创粉丝点击