使用Unicode重命名文件

时间:2014-04-22 05:00:51

标签: c++

如何将unicode字符放入文件名? 我有一个ostringstream用于通过ofstream定义文件名,但我不能使用unicode字符。这样做最简单的方法是什么?以unicode格式重命名?请解释我将如何这样做。

2 个答案:

答案 0 :(得分:2)

/* This program attempts to rename a file named

* CRT_RENAMER.OBJ到CRT_RENAMER.JBO。对于这个操作  *要成功,必须存在名为CRT_RENAMER.OBJ的文件  *名称为CRT_RENAMER.JBO的文件不得存在。  * /

#include <stdio.h>

int main(void)
{
   int  result;
   char old[] = "CRT_RENAMER.OBJ", new[] = "CRT_RENAMER.JBO";

   /* Attempt to rename file: */
   result = rename(old, newArray);
   if(result != 0)
      printf("Could not rename '%s'\n", old );
   else
      printf("File '%s' renamed to '%s'\n", old, newArray);
}

答案 1 :(得分:0)

你的问题不清楚。如果你想放置unicode字符 - 在STL中有任何字符串/流类,它的unicode等价。 std :: string / std :: wstring,std :: stringstream / std :: wstringstream。如果你是std :: wstringstream,那么在这里你将如何将unicode字符放入其中:

std::wstringstream wideStream;
wideStream << L"Hello, world";
std::wstring wideString = wideStream.str();

希望这有帮助。

相关问题