I was programming in C++ when I noticed some... odd behavior when taking in console input. Let me explain.
#include <iostream>
int main(int argc, char *argv[]) {
if (argc == 1) {
std::cout << "Hello!\n";
}
if (argc >= 2) {
}
}
Pretty simple program, right? Now, when I type in "programName ^" I get a cryptic message, saying "More?" on the console window. On pressing enter, it prompts again and on pressing it once more it closes the application.
Out of curiosity, I tried doing this on some other console input applications I have made and they all do this. What does "More?" mean? I never coded that in, so why is it there?
I'm able to reproduce the behavior with g++ on Windows.
The DOS shell is interpreting "^" as some kind of "continuation character".
The ^ symbol (also called caret or circumflex) is an escape character in Batch script. When it is used, the next character is interpreted as an ordinary character.
Look here for more details:
https://forums.tomshardware.com/threads/when-did-become-special-on-the-command-line.1071200/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With