| View previous topic :: View next topic |
| Author |
Message |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Thu Sep 20, 2007 11:19 am Post subject: help c++ something is wrong |
|
|
well i started to learn c++ right now ... and i got 1 problem like always ..
well i compiling the program and no errors but when i run it it only dissapare in 1 sec
but if i press run in the program it work
whats the problem with my comp .... it happening with allthing i compiling in c++
but if i press run in the program it work but if i compile it dissapare in 1 sec -.-
tested dev c++ ,Quincy 99 to compile them =/
| Code: |
#include <iostream>
int main()
{
// write to the screen
std::cout << "My first C++ program";
return 0;
}
|
_________________
dont complain about my english...
1*1 = 2?
Last edited by ups2000ups on Thu Sep 20, 2007 11:20 am; edited 1 time in total |
|
| Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Thu Sep 20, 2007 11:20 am Post subject: |
|
|
Run them through CMD or _getch
_________________
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Thu Sep 20, 2007 11:23 am Post subject: |
|
|
| UnLmtD wrote: | | Run them through CMD or _getch |
you mean compile them by cmd
or
"start C:\Quincy99\Programs\Chap02\pr02001"
oO well "start C:\Quincy99\Programs\Chap02\pr02001" then it happening the same
or tell me how to do it =p well im a noob at this ...
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Sep 20, 2007 11:26 am Post subject: |
|
|
Windows+R
cmd
Click OK
cd "your folder goes here" (Note the quotation marks.)
(then just type the name of your exe eg.) myprogram.exe
In your case:
Windows+R
cmd
Click OK
cd "C:\Quincy99\Programs\Chap02\"
pr02001.exe
OR just:
Windows+R
cmd
Click OK
"C:\Quincy99\Programs\Chap02\pr02001.exe"
The .exe isn't necessary, but I added it there to avoid confusion.
Last edited by Jani on Thu Sep 20, 2007 11:29 am; edited 1 time in total |
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Thu Sep 20, 2007 11:29 am Post subject: |
|
|
Thanks =D
but why cant i open it like an exe ? oO
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Sep 20, 2007 11:31 am Post subject: |
|
|
| ups2000ups wrote: | | but why cant i open it like an exe ? oO | Because autoclose is a feature of Windows XP command shell. Put #include <conio.h> in your code and "::_getch();" in the very last line before return. (No quotation marks.)
| Code: | #include <iostream>
#include <conio.h>
int main()
{
// write to the screen
std::cout << "My first C++ program";
::_getch();
return 0;
} | Note that ::_getch() isn't portable! I guess the best portable way would be doing std::cin.ignore(); and std::cin.sync();. I'm not sure tho.
Btw.. Thanks for the rep ;)
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Sep 20, 2007 11:55 am Post subject: |
|
|
| Code: |
loop:
goto loop;
return 0;
|
Roflmao.
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Thu Sep 20, 2007 12:19 pm Post subject: |
|
|
| noz3001 wrote: | | Code: |
loop:
goto loop;
return 0;
|
Roflmao. |
okaj ur way is better -.- or atleast easier to remember =p
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Sep 20, 2007 12:21 pm Post subject: |
|
|
| ups2000ups wrote: | | noz3001 wrote: | | Code: |
loop:
goto loop;
return 0;
|
Roflmao. |
okaj ur way is better -.- or atleast easier to remember =p |
Trust me, it's not.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Sep 20, 2007 1:14 pm Post subject: |
|
|
that would never end would it?
_________________
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Thu Sep 20, 2007 4:24 pm Post subject: |
|
|
system("pause"); would be the better way. Since you are already using iostream, you don't need to include anything else. You also don't have to use goto. It also gives you a message "Press any key to continue".
| Code: |
#include <iostream>
int main()
{
system("pause");
}
|
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Sep 20, 2007 4:37 pm Post subject: |
|
|
| killersamurai wrote: | system("pause"); would be the better way. Since you are already using iostream, you don't need to include anything else. You also don't have to use goto. It also gives you a message "Press any key to continue".
| Code: |
#include <iostream>
int main()
{
system("pause");
}
|
|
Ignore this guy, Jani gave the correct method.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Sep 20, 2007 4:53 pm Post subject: |
|
|
Do cin.get(). Trust me, using labels is horrible, it shouldn't rly ever be used but there are certain times I guess you can use them. But just do this.
| Code: |
#include <iostream>
using namespace std;
int main()
{
cout<<"My first C++ program.\n";
cin.get();
}
|
Now it won't automaticly close and it will only close now if you click enter.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Sep 20, 2007 5:01 pm Post subject: |
|
|
| Code: | #include <iostream>
using namespace std;
int main()
{
cout<<"My first C++ program.\n";
cin.ignore();
cin.get();
} |
use cin.ignore() in situations where you prompt for info
_________________
|
|
| Back to top |
|
 |
|