Parsing command line arguments in a unicode C++ application

前端 未结 4 1550
春和景丽
春和景丽 2021-01-02 05:37

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

Unicode apps have a main like this:

int _tmain(int         


        
4条回答
  •  长发绾君心
    2021-01-02 06:23

    A TCHAR is a character type which works for both ANSI and Unicode. Look in the MSDN documentation (I'm assuming you are on Windows), there are TCHAR equivalents for atoi and all the basic string functions (strcpy, strcmp etc.)

    The TCHAR equivalient for atoi() is _ttoi(). So you could write this:

    int value = _ttoi(argv[1]);
    

提交回复
热议问题