This question already has answers here:
Preventing console window from closing on Visual Studio C/C++ Console application
(24 answers)
How to stop C++ console application from exiting immediately?
(35 answers)
Closed 4 years ago.
I can see the output when I use the compiler but when I use the exe separately, it closes after finishing, so I can't see the output. What can I do to make the exe stay open?
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
setlocale (LC_ALL,"hun");
cout<<"b: ";
double b,a,c,x1,x2,valami,gyokalattvalami,minusb,kettoa;
cin>>b;
cout<<"a: ";
cin>>a;
cout<<"c: ";
cin>>c;
valami=pow(b,2)-4*a*c;
//cout<<valami <<endl;
gyokalattvalami=pow(valami,0.5);
//cout<<gyokalattvalami;
minusb=b-b*2;
//cout<<minusb;
kettoa=2*a;
//cout<<kettoa;
x1=(minusb+gyokalattvalami)/kettoa;
x2=(minusb-gyokalattvalami)/kettoa;
system("CLS");
cout<<"X1=" <<x1 <<endl;
cout<<"X2=" <<x2;
}
Related
This question already has answers here:
What is the Best Practice for Combating the Console Closing Issue?
(11 answers)
Closed last month.
I have 1 simple code in c++. That code calculate sum of 2 entered numbers. I convert that code to .exe for running windows. My problem is it will work but it doesn't show sum. After entering second number program closes immediately. I have no idea why this happen.
Here is my code:
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout << "Please enter first number \n";
cin >> a;
cout << "Please enter second number \n";
cin >> b;
int z = a + b;
cout << "Sum of these numbers are: " << z;
}
I find solution via command prompt. But I want to completely run my .exe file without command prompt
Closing the console after program finishes is a normal behaviour when you don't start it from the terminal. You could delay the closing of console by using
std::cin.get(). The function waits until recieving input from terminal, so when you press any key, the program will end and console will close
This question already has answers here:
Why does my cout output not appear immediately?
(2 answers)
XCode 4 only displaying cout statements with endl
(1 answer)
C++ not showing cout in Xcode console but runs perfectly in Terminal
(2 answers)
Xcode not showing console output; How do you flush the console?
(1 answer)
No output for console application in Xcode
(1 answer)
Closed 5 years ago.
The code below works fine on Windows, but when I compile it on Mac's Xcode, I don't get any output.
#include <iostream>
#include <stack>
using namespace std;
int main(int argc, const char * argv[]) {
stack<int> S;
S.push(5);
cout << S.top();
return 0;
}
This question already has answers here:
Preventing console window from closing on Visual Studio C/C++ Console application
(24 answers)
Closed 5 years ago.
I have a piece of code that should output some text, but when I run it an empty window pops up. I want to create characters on a window. Can someone tell me why this doesn't happen?
Here is the code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
char str[] = "Hello C++";
cout << "Value of str is : " << str << endl;
return 0;
}
Thanks
Your code is fine -- but the window will automatically close when the code finishes its execution.
Consider adding a cin at the end of your code to prevent the window from closing.
int t;
cin >> t;
This question already has answers here:
Wait until user presses enter in C++?
(3 answers)
Closed 7 years ago.
I am a total newbie to C++ and I need to have 3 line of text and after every line I have to ask the user to press enter to continue. How can I do it?
Here is the code that I have so far:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Es esmu dators.";
std::cout << "Es zinu C++.";
std::cout << "C++ ir programmesanas valoda";
}
You can use getchar() after each line. To use getchar() you must include cstdio.
Example code:
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
std::cout << "Es esmu dators.\n";
getchar();
std::cout << "Es zinu C++.\n";
getchar();
std::cout << "C++ ir programmesanas valoda\n";
}
From this answer:
Several ways to do so, here are some possible one-line approaches:
Use getch() (need #include ).
Use getchar() (expected for Enter, need #include ).
Use cin.get() (expected for Enter, need #include ).
Use system("pause") (need #include ).
PS: This method will also print Press any key to continue . . . on the screen. (seems perfect choice for you :))
You should also perform a quick search on the site to see if your question has been asked before, going forward.
This question already has answers here:
execute C++ from String variable
(6 answers)
Closed 7 years ago.
Hi I have been trying to make a program that will ask for the users input and whatever the user types it will execute it as a command. Sort of like CMD
#include <iostream>
#include <string>
using namespace std;
string A;
int main(){
for (int i = 0; i > -1; ++i){
cout << "Command: ";
cin >> A;
// Here Would Be The Code
cout << "Command Executed!";
}
}
Here is what i imagine a possible output (if it worked)
Command: cout << "Test";
Test
Command Executed!
You can use the system function.
http://www.cplusplus.com/reference/cstdlib/system/
system("command")