How can i printing all the cases in vscode console [duplicate] - c++

This question already has answers here:
When I run the code in vs code, the results seem to appear and then disappear quickly, how do I fix this?
(2 answers)
Why does my console application disappear immediately
(7 answers)
Console window disappear immediately [duplicate]
(1 answer)
C++ Setup For VS Code [duplicate]
(1 answer)
Closed 4 months ago.
I don't understand. I wrote a "hello world" program and run it, console only shows up immediately and turns itself off.
You guys can help me please
I want to use vscode console to input the result then print it with the line "press any key to countinue" like DevC++. I want it to not turn itself off when I haven't entered all the cases

After your while loop, add: _getch();
std::cout << "press any key to countinue...";
int c = _getch();
Then the application will wait untill you press a key.
What's happening is when the caSe is zero the application leaves the loop. Then there is no code left and the application exits.
But please remove the second image and replace the first with your code. We love to copy your code to help you out. The programs output you should write out too, although in this case not needed when you write clearly what is happening. And state clearly what you want to do.

Try adding this in the last place.
system("pause");

Related

Windows console closing immediately after running a c++ code [duplicate]

This question already has answers here:
How to stop C++ console application from exiting immediately?
(35 answers)
Closed 5 years ago.
I just started using Visual Studio to write C++ code on Windows 10 and I am using the console application template. My problem is that the console disappears immediately after showing the output of my program even when I simply run a "hello world" example. I tried all kinds of tricks to implement delay but no success.
I usually put a std::cin line just before main returns. This will cause it to wait for input before continuing.
You can do the following( assuming that you are not waiting for user input, in that case you can just follow Rich's answer ) :
Run it in debugging with a breakpoint on the last line before the main returns.
Use a system("pause") at the end before the main returns.( suggesting this just because it's just a hello world program in Visual Studio )
A great way to pause the console in Visual Studios for your purposes is to use system("pause"); Though its not portable to other OS and some anti-virus systems don't like it. For your purposes it should work well and is easy to see what the line does.
Hope this helps.

How to hide my input on my terminal? [duplicate]

This question already has answers here:
Hide user input on password prompt [duplicate]
(3 answers)
Closed 6 years ago.
I'm on Ubuntu with C++
How do I hide the red box (user input) as shown in the image above on my terminal ?
char *MESSAGE=getpass("");
the code above would leave a blank line after each input and I dont want the message to be hidden while the user typing the message.
In short, I want the message to be visible as I'm typing the message but goes invisible on my terminal as soon as he entered.
EDIT : Can someone please enlighten me on how this question is duplicated to that thread?.
You could clear the terminal after a message has been sent and reprint the whole chat afterwards.
If you can print the name first and then read the input message, I think your problem might be solved. Have you tried that?
You cannot do that in a reliable and portable way with only functions from the standard C library, not even with Posix one.
If you now that you are using a Windows console, the Windows console functions could allow you to erase specific portions of the screen, if you know that you are using a terminal emulator conformant to one standart (VT100, xterm, ...) you can output special control sequence to do the same.
The only portable way would be to use a screen management library like curses that will do the low level work for you.

C++ Terminal Closes on Enter [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to stop C++ console application from exiting immediately?
Forgive me for my rather extreme newbie-ness in the field of C++ but here goes. :)
When I run say for example this code in a terminal:
int g;
cout << "Please enter an integer value: ";
cin >> g;
cout << "The value you entered is " << g;
...to you C++ experts out there, obviously this accepts a value from the user's input and then displays in the output. However, right after I "submit" my input and click enter, I see the output for a mere millisecond and then the terminal closes. Anyway I could stop the terminal from closing so I could actually have a chance to see the result?
I'm using Visual Studio on Windows 7.
Thanks!
If you're working on Windows, you can add the line system("pause"); at the end of the program.
Or cin.get() if on Linux
Depends on what you're using. For Windows it is common to use a breakpoint (__debugbreak) but for Unix people usually just run it in an existing terminal which does not close.
I don't know what kind of OS do you use, but the function is similary
start a terminal in Linux oder a Commandline in Windows.
Switch with the command "cd" to the directory where the Program lies.
Linux:
./myProgram
Windows
myProgram
The Terminal which you started wouldn't be closed ;)

C++ Run and closes when finish? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to stop C++ console application from exiting immediately?
I'm currently learning C++ and cant figure out how to stop the application from exiting when I want to show the user some data, and have time to read it. How may i do that?
Update: Somehow I pause the application and when the user click a button it exits.
I assume you're on Windows.
This can turn into a long debate, but generally there are two main ways people do it:
(recommended) Add cin.get(); to the end of your program. This will cause your program to stop until the user hits enter, then it will continue and quit.
This will work on Windows and Linux.
Add system("PAUSE"); at the end of your program. This will cause your program to print something like Press any key to continue. . . and when you hit a key, the program will continue and quit.
There is a chance that the PAUSE command doesn't do that and can order pizza, launch the missiles, or something else.
This only works for Windows but you won't need it when you go to linux anyway.
std::cout << "Press enter to exit" << std::endl;
cin.get();
exit(1);
If you want to pause your program until the user presses a key, you can use cin.get(). But really, the program should terminate when it's finished. Otherwise, it's useless in pipelines and the like.
If your program's window goes away when it's finished, then something is wrong with the way you launched it. Whether the window stays when the program is done is up to the thing that launches the program and sets up the window, not the program. This problem is usually caused by launching CLI programs from a GUI. If you want to launch from a GUI, write a GUI program. Otherwise, launch terminal programs from the terminal.
Do not use system("pause");. It makes your program unportable. And if you ever run it on a system whose pause command does something other than what you want, you may have a very angry user on your hands.
Do not use getch. That's a Windows console function and a Curses function. It's not part of C++. (Unless you are specifically developing for a platform that has this function and you are sure it does what you want. But this one function would be a really silly reason to make your program unportable.)

If your program quits almost immediately on running, how to make sure the console window stays open to read output? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to keep the console window open in visual c++?
I have a program that runs on my home machine, but on another machine it quits instantly when being executed. The console window opens and closes so fast that I can't read the output. How can I make sure this output stays visible, so I can read what it's trying to tell me?
Since it's a console application run it from a cmd window.
You can set Visual Studio to break when an exception is thrown (of course this will only work if an uncaught exception is what is causing your program to terminate early).