解析unicode C ++应用程序中的命令行参数 [英] Parsing command line arguments in a unicode C++ application

查看:185
本文介绍了解析unicode C ++应用程序中的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果应用程序是unicode,我如何解析传递给应用程序的整数作为命令行参数?

How can i parse integers passed to an application as command line arguments if the app is unicode?

Unicode应用程序具有这样的主体:

Unicode apps have a main like this:

int _tmain(int argc, _TCHAR* argv[])

argv [?]是一个wchar_t *。这意味着我可以使用atoi。如何将它转换为整数?是stringstream最好的选项?

argv[?] is a wchar_t*. That means i can´s use atoi. How can i convert it to an integer? is stringstream the best option?

推荐答案

如果你有一个TCHAR数组或指向开始的指针, code> std :: basic_istringstream 使用它:

if you have a TCHAR array or a pointer to the begin of it, you can use std::basic_istringstream to work with it:

std::basic_istringstream<_TCHAR> ss(argv[x]);
int number;
ss >> number;

现在, number 是转换的数字。这将工作在ANSI模式(_TCHAR类型定义为 char )和Unicode(_TCHAR是typedef`ed到你说的wchar_t)模式。

Now, number is the converted number. This will work in ANSI mode (_TCHAR is typedef'ed to char) and in Unicode (_TCHAR is typedef`ed to wchar_t as you say) mode.

这篇关于解析unicode C ++应用程序中的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆