0

Here's the following main method:

int main(int argc,char** argv)
{
    std::string expression=argv[1];
    for(int i=2;i<argc;i++)
    {
        expression+=' ';
        expression+=argv[i];
    }
    std::cout << expression << std::endl << std::endl;
    Expression* expr = Expression::build(expression.c_str());
    std::cout << expr->evaluate() << std::endl;
    delete expr;
    return 0;
}

Which, for some reason works great most of the time, but see this input / output examples:

D:\Tyler\Desktop>a 2**3
2**3

8

D:\Tyler\Desktop>a 2 ** 3
2 10284556_10203827451228798_9031461414658797199_o.jpg 15686-vanille.p3t 18
865-MiraiNikki.p3t 20777-MIRRORSEDGE2AnimatedTheme.p3t [APE] gras.gpl [Irfa
nView] [APE] gras.pal a.exe arboles_FM.png calc.c calc.cpp couch.png deskto
p.ini gras.pal hackzorz log.txt montanas_FM.png p3textractor p3textractor.z
ip PALLET TOWN.bmp PALLET TOWN.png Pokemon FireRed.bak Pokemon FireRed.gba
Pokemon FireRed.ini Pokemon FireRed.zip ROM Hackers GBA Tool Pack roms send
eros_cope.png senderos_FM.png Thumbs.db Tileset0.bmp Tileset0.pal untitled.
bmp untitled.PNG wdps 3

I have a feeling that this is some kind of windows thing, or am I missing something critical here?

Full Metal
  • 47
  • 1
  • 8
  • 1
    possible duplicate of [Problem of \* in Command line argument](http://stackoverflow.com/questions/2718873/problem-of-in-command-line-argument) – Raymond Chen Jun 04 '14 at 04:57
  • 1
    You can fix your code by using `GetCommandLine()` instead of `argv`, though note that this will also include the executable. (That is, it will return `a 2 ** 3` rather than `2 ** 3`.) – Harry Johnston Jun 05 '14 at 22:31
  • I had a feeling there would be a complicated way to get this to work. I guess a few ifdef's aren't so horrible, but I hate using windows.h ;_; Thank you for pointing that out, I wasn't aware that was an actual function, as it seems a little bit unnecessary beyond weirdly specific use-cases. – Full Metal Jun 06 '14 at 02:08

1 Answers1

1

** is a classic "wildcard" in many shells, windows included.. It will be replaced with a list of all files in the current directory.

Therefore, you can do del * to delete all files. Using multiple *'s is the same as single *'s.

Yeraze
  • 3,021
  • 3
  • 25
  • 42
  • Huh, I'd known about a single asterisk, but never heard of the double asterisk being a wildcard. Thanks! (: – Full Metal Jun 04 '14 at 05:20
  • 1
    This is incorrect; the Windows shell does *not* do any such replacement. The executable itself is responsible for doing so if appropriate. Typically this is handled by the runtime library. – Harry Johnston Jun 05 '14 at 22:27
  • Are you saying that GCC's CRT is responsible for replacing ** with the directory listing? If that were the case, wouldn't it make more sense for it to adopt the linux wildcard [ a single asterisk? ] I feel pretty confident that my code isn't doing that, and I tried running `del **.exe` and it worked well enough. Can you explain a little bit more what you mean when you say it's handled by the runtime library? – Full Metal Jun 06 '14 at 02:07