none
命令行程序每次只打印第一个字符? RRS feed

  • 问题

  • 费解啊,现在的问题是,主函数是

    int _tmain(int argc, char* argv[], char* envp[]);
    
    

    通过

    printf("%s\n\n",argv[1]);
    
    

    打印发现,为什么每次只打印第一个字符?

    比如输入

    test.exe 564 56 6

    它仅仅输出 5

    ??????

    好像没有问题吧?

    环境是win 7 的cmd,管理员运行也不好使。

    发现在XP能通过cmd传入参数的程序,在win7 cmd 下也失效。

    2010年6月8日 13:29

答案

  • int wmain(int argc, wchar_t *argv[])
    {
        for (int i = 0; i < argc; i++)
        {
            wprintf(L"%s\n", argv[i]);
        }

        return 0;
    }



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年6月8日 14:23
    版主

全部回复

  • int wmain(int argc, wchar_t *argv[])
    {
        for (int i = 0; i < argc; i++)
        {
            wprintf(L"%s\n", argv[i]);
        }

        return 0;
    }



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年6月8日 14:23
    版主
  • 经过测试,好用,谢谢。
    2010年6月9日 2:13