How to display "Press any key to continue" in C++?

Asked

Viewed 4,952 times

2

In C, I put "Press any key to continue" with the getchar(). command in C++, as I do?

2 answers

5


You can use the function getchar() even.

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    cout << "Pressione qualquer tecla para continuar..." << endl;
    getchar();
    return 0;
}
  • It doesn’t work because if some gringo goes to use the code, he won’t know what it says.

  • 4

    @Cypherpotato As far as I understand the author asked only how to display the text "Press any key to continue...". In my view the example answers exactly what was asked. Agree? + 1 to answer.

  • Yes, at a certain point it’s right. But if he’s going to have to distribute, he’ll have to use the guy’s method below.

  • @Cypherpotato I didn’t understand, distribute exactly what and for what? If you have any suggestions for better use please post an answer, I guarantee that a vote will already have (depending on the answer), my (:

  • @Cypherpotato Works, works =) AP did not explain this fact you said, but if you need to display the text in another language, you can use the cin.get(). Or if you need something more elaborate, use the function GetSystemDefaultUILanguage to detect the language of S.O and display the text in that language. About system("pause"), is something just Windows, take a look too in this matter of the OS.

  • Yeah, but he wouldn’t have to wear one Switch for each language of the system, would pick something more dynamic, correct?

  • @Cypherpotato If using the function GetSystemDefaultUILanguage or GetUserDefaultUILanguage, she will return a language identifier, that identifier you compare with a specific language, for example French, and print the text in this language. =)

  • @Cypherpotato I really just wanted to use this. I won’t have to distribute at the moment.

  • I don’t use C++, sorry...

  • Nothing to be sorry about, @Cypherpotato =)

  • 1

    Thank you haha :D

Show 6 more comments

0

To display the "Press any key to continue", you must include the library <cstdlib> and add system("pause") at the desired location.

Note, however, that this function does not return the pressed key, only pause the execution and resume after pressing.

  • I’m in a Linux environment. The system("pause") won’t work here. But I did. I included the <stdio library. h>, same as C, in C++, kept my <iostream> and put getchar();

  • I wanted to take out this message from "Press any key to continue" and even then the program take the break, have as?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.