在主函数中使用wchar_t
using wchar_t in the main function
在Visual Studio 2017中使用main函数C++如下所示是错误的吗?
int main(int argc, wchar_t* argv[])
因为我的程序可以接收特殊字符。
请去阅读GetCommandLine
上的备注部分:
用 C 编写的 ANSI 控制台进程可以使用 main 函数的 argc 和 argv 参数来访问命令行参数。ANSI GUI 应用程序可以使用 WinMain 函数的 lpCmdLine 参数来访问命令行字符串,不包括程序名称。main 函数和 WinMain 函数不能返回 Unicode 字符串。
用 C 编写的 Unicode 控制台进程可以使用
wmain()
或_tmain()
函数来访问命令行参数。Unicode GUI 应用程序必须使用 GetCommandLineW 函数来访问 Unicode 字符串。若要将命令行转换为 argv 样式的字符串数组,请调用 CommandLineToArgvW 函数。
是的,但是如果您需要执行输入和输出操作,也许您需要添加std::setlocale(LC_ALL, "");
,因为默认情况下它仅支持最基本的英文字符输出。 例:
int wmain(int argc, wchar_t* argv[])
{
std::setlocale(LC_ALL, "");
wstring str = argv[1]; //if argv[1] contains unicode characters, such as"你好"
wcout << str << endl;
return 0;
}
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 如何将CString转换为使用WCHAR的Windows API和自定义函数?
- C++通过引用 WCHAR** 传递到函数中
- 在WCHAR*和wstring之间转换,而不使用构造函数
- 如何用WCHAR*在消息框中显示c#中的C函数