我尝试着写一些wchar_t *到文件,但编译后的程序的命令行输出如下所示。当试图写希腊字符串时,程序基本上是挂起的。下面写入wofstream会产生异常
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <wchar.h>
using namespace std;
int main(int argc, char **argv)
{
printf("%s\n",setlocale(LC_ALL,""));
wofstream f("xxx.txt", ios::out);
if(f.is_open())
{
try
{
f.write(L"good",4);
f.flush();
f.write(L"καλημερα",8);
f.close();
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e <<endl;
}
printf("hello world\n");
return 0;
}
}
为什么
el_GR.UTF-8
terminate called after throwing an instance of 'int'
Ακυρώθηκε (core dumped)
源代码?
这是一个错误,因为没有在输入输出流应该永远抛出一个int。什么是编译器和整个系统?有警告吗?源代码的编码是什么?最后,'e'的价值是什么? –
e的值是20.我使用g ++编译时没有警告。这看起来应该是一种初始化。 –