When I run a compiled program with more than one commandline argument, the program returns nothing

When I run anything with just one argument, like ./a -a, or ./a asdfsa, the program runs normally.

But when I do anything with more than one argument, like ./a asdf asdf, nothing happens; basically it's as if the program immediately returned, without executing code

Here is a simple version of my code:
1
2
3
4
  int main(int argc, char** argv) {
     cout <<"test";
     return 0;
}


When I run with two or more arguments, the "test" does not get displayed, the program just returns.

There is more to my code, but I can't see any reason why it would affect the outcome, so I'm not including it.

The cout is the first line of my main(), so I don't think any subsequent code would affect it anyhow.
Last edited on
what's calling your main function?
I just compile the .cpp, file, and if the executable say is named program, then type ./program into the terminal.
What happens if you change the line to std::cout << "test" << std::flush ;?
Thanks JLBorges, that got it to work. I also tried endl, and that worked too (apparently it also flushes).
> There is more to my code, but I can't see any reason why it would affect the outcome, so I'm not including it.

The code probably contains constructs that engender undefined behaviour when argc == 3.
Otherwise, std::cout would have been flushed before it is destroyed (when the program ends normally).
Last edited on
Topic archived. No new replies allowed.