|
-
Feb 26th, 2003, 09:47 AM
#1
Thread Starter
Addicted Member
console program
Why this program works fine with bc++ but it exit just ater getting the value of x from console in vc++?
#include <iostream.h>
void main()
{
int x;
cin >> x;
// cout<<endl;
x=x-10;
cout << x;
cin.get();
}
-
Feb 26th, 2003, 10:57 AM
#2
Monday Morning Lunatic
Works fine for me. Try starting it from a command prompt. You're not seeing the printout because the program closes.
Also, you're horribly non-standard there:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int x;
cin >> x;
x = x - 10;
cout << x << endl;
system("pause");
}
The cin.get() at the end didn't work, so I used the method of choice for most people. Note that that will only work on DOS or DOS-compatible systems.
When you run a console program from VC++, it automatically adds its own prompt anyway.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 26th, 2003, 08:42 PM
#3
Thread Starter
Addicted Member
Thank U very much. It works (waits until we hit any key in bc++) but not in vc++.
#include <iostream.h>
#include <conio.h>
void main()
{
int x;
cin >> x;
cout<<endl;
x=x-10;
cout << x;
//cin.get();
while(!kbhit());
}
-
Feb 27th, 2003, 03:43 AM
#4
Monday Morning Lunatic
You missed my second point completely. Don't use <iostream.h>. Technically you shouldn't use <conio.h> either, but...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 27th, 2003, 04:47 AM
#5
Hyperactive Member
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int x;
cin >> x;
x = x - 10;
cout << x << endl;
system("pause");
}
-
Feb 27th, 2003, 06:24 AM
#6
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|