C++ C++;使用Unicode时出现wmain函数错误
我曾试图使用C++ C++;使用Unicode时出现wmain函数错误,c++,unicode,mingw,wmain,C++,Unicode,Mingw,Wmain,我曾试图使用wmain进行简单的测试代码来练习WCS字符串(不是MBCS),但我一直都会出错,但我不知道为什么 这是我的密码 #include <iostream> #include <stdio.h> using namespace std; int wmain(int argc, wchar_t * argv[]) { for (int i = 1; i < argc; i++) { fputws(argv[i], stdout);
wmain
进行简单的测试代码来练习WCS字符串(不是MBCS),但我一直都会出错,但我不知道为什么
这是我的密码
#include <iostream>
#include <stdio.h>
using namespace std;
int wmain(int argc, wchar_t * argv[])
{
for (int i = 1; i < argc; i++) {
fputws(argv[i], stdout);
fputws(L"\n", stdout);
}
return 0;
}
#包括
#包括
使用名称空间std;
int wmain(int argc,wchar_t*argv[])
{
对于(int i=1;i
它给出了错误消息
c:/mingw/bin/./lib/gcc/mingw32/6.3.0/../../../../../libmingw32.a(main.o):(.text.startup+0xa0):未定义对`WinMain@16'
collect2.exe:错误:ld返回了1个退出状态
为什么会崩溃?我无法找到为什么会出现这个错误。<强> >代码> WMeN//C>> /Sturn>是一个VisualC++语言扩展,用于处理Windows中的UTF 16编码命令行参数。 但是,您正在使用的现代MinGW g++编译器通过选项
-municode
支持它
对于不支持它的编译器,您可以轻松编写几行标准的main
,调用Windows的GetCommandLineW
和CommandLineToArgvW
,然后调用wmain
函数
调用
wmain
的标准main
示例,如上所示:
#ifdef USE_STD_MAIN
#include <stdlib.h> // EXIT_...
#include <windows.h> // GetCommandLineW, CommandLineToArgvW
#include <memory> // std::(unique_ptr)
auto main()
-> int
{
int n_args;
wchar_t** p_args = CommandLineToArgvW(GetCommandLineW(), &n_args );
if( p_args == nullptr )
{
return EXIT_FAILURE;
}
const auto cleanup = []( wchar_t** p ) { LocalFree( p ); };
try
{
std::unique_ptr<wchar_t*, void(*)(wchar_t**)> u( p_args, cleanup );
return wmain( n_args, p_args );
}
catch( ... )
{
throw;
}
}
#endif
#如果定义使用标准主
#包括//EXIT\u。。。
#包括//GetCommandLineW、CommandLineToArgvW
#包括//标准::(唯一的\u ptr)
自动主机()
->int
{
int n_args;
wchar\u t**p\u args=CommandLineToArgvW(GetCommandLineW(),&n_args);
if(p_args==nullptr)
{
返回退出失败;
}
const auto cleanup=[](wchar_t**p){LocalFree(p);};
尝试
{
std::unique_ptr u(p_参数,清除);
返回wmain(n参数,p参数);
}
捕获(…)
{
投掷;
}
}
#恩迪夫
try
-catch
似乎没有任何作用,它的目的是保证对wmain
调用局部变量的析构函数,如这里的u
免责声明:我刚刚写了那个代码。它没有经过广泛的测试。谢谢您的回复。但是当我将wmain()更改为main()时,我的代码运行良好。。。所以我猜这和wmain()有关。我无法用给定的链接解决问题。可能重复的,等等。感谢您的回答!祝你今天愉快:)