Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"More?" in C++ when taking in console input

Tags:

c++

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?

like image 790
avighnac Avatar asked Mar 02 '23 09:03

avighnac


1 Answers

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/

like image 111
paulsm4 Avatar answered Mar 12 '23 11:03

paulsm4