解析unicode C ++应用程序中的命令行参数 [英] Parsing command line arguments in a unicode C++ application
问题描述
如果应用程序是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屋!