Avatar of davidhq
davidhq asked on

Command line parsing (UNICODE)

Hi!

I have this simple test program in Visual C++ (VS2005)

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
      for(int i = 0; i < argc; i++)
      {
            wcout << "|" << argv[i] << "|" << endl;
      }

      wcout << L"TEST: ¬aa~";

      return 0;
}

Character Set in project properties is set to: "Use Unicode Character Set".

When I start the program: "uni a b c", I get:

|uni|
|a|
|b|
|c|
TEST:

if I try "uni aa  ~~", I get just:
|uni|
|


So even this basic example is not working.. what am I doing wrong? thank you very much
.NET ProgrammingVisual C++.NETC++

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
ASKER
davidhq

My unicode arguments and test string didn't make it to the page .. so let's just pretend I sent some unicode characters on the command line.. and they didn't get printed out.. they even confused the loop :(

oh and I also tried to set "cp 65001" in cmd.

THANK YOU
evilrix

I think the problem is possibly that the standard DOS shell doesn't understand Unicode output. Try downloading and installing PowerShell and then try it...

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
ASKER CERTIFIED SOLUTION
itsmeandnobodyelse

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
evilrix

Like I said, I think (not 100% sure) PowerShell is Unicode friendly -- you'd have to test it :)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
evilrix

Try streaming to a file and edit with a unicode friendly editor (notepad???) -- it should work!

#include <fstream>

int _tmain(int argc, _TCHAR* argv[])
{
      int retval = 0;

      try
      {
            std::wofstream wofs("output.txt");

            if(!wofs.is_open()) { throw -1; }

            for(int i = 0; i < argc; i++)
            {
                  wofs
                        << "|"
                        << argv[i]
                        << "|"
                        << std::endl;

                  if(!wofs.good()) { throw -2; }
            }

            wofs
                  << L"TEST: ¬aa~"
                  << std::endl;

            if(!wofs.good()) { throw -3; }
      }
      catch(int const & errval)
      {
            retval = errval;
      }
      catch(...)
      {
            retval = -4;
      }

      return retval;
}

-Rx.
ASKER
davidhq

Thank you both!  I had to accept the solution that just tells me "it cannot be done easily" - I'll pass that on to a requestor that uses unicode chars in file names ;)

evilrix: sorry, I didn't have time to try your solutions but maybe the will come handy in the future. THANK YOU
evilrix

Um, I'm just wondering why I wasn't credited with this as I actually provided the correct answer as the very first response!

>> evilrix: I think the problem is possibly that the standard DOS shell doesn't understand Unicode output

I also provided example code to prove this! At the very least I think this should have been a point split between Alex and myself!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
itsmeandnobodyelse

>>>> At the very least I think this should have been a point split
>>>> between Alex and myself!
I think at a long run all "no-splits" will get compensated somehow. I would bet that you yesterday got a 'good answer' where a split would have been appropriate as well  ...  ;-)
evilrix

Maybe... since it's you Alex you can have this one ;)
ASKER
davidhq

evilrix: I was thinking about the point split. Here is why I didn't do it:

- couldn't find the feature fast enough and since I'm a new user, I wasn't really sure such a feature exists
- didn't have time to test your solution so I cannot really judge it

In the future I will play with a split-points feature once I find it!

thank you again!

david

Your help has saved me hundreds of hours of internet surfing.
fblack61
evilrix

Regardless of that my original post stated what the problem was... all Alex did was confirm this and elaborate! Never mind, it's done now.