I'm trying the super basics and the command prompt keeps disappearing

  • Thread starter UltimateSomni
  • Start date
  • Tags
    Basics
In summary: Dev-C++ 4.9.9.2 or newer).In summary, when trying to compile and run the program from the command prompt, it only stays up for a second and then goes away. I've tried copying and pasting the path to the executable, moving the program to the root directory, and running from there, but nothing seems to work.
  • #1
UltimateSomni
62
0
For the second part of the tutorial, I'm suppose to compile and run to see what the output is. But, each time I click compile and run the command prompt shows up for less than a second and then goes away. What am I suppose to do?
 
Technology news on Phys.org
  • #2
Welcome to PhysicsForums!

I'll assume that you're doing this in Windows. Open up the command prompt (Start > Run > cmd) and then execute the compiled program (the .exe that's generated) from the command prompt. If you're lazy like me, you can copy the path of the .exe by right clicking on it and opening up its properties. You should then be able to paste this in the command prompt.
 
  • #3
How do I execute the compiled program from the command prompt?

Also, is there anyway to fix this problem for the future?
 
  • #4
That's the default behaviour of the command prompt. Let's say your program is on your desktop, and named foo.exe

From the command prompt, you'd type in:
c:\documents and settings\(username)\desktop\foo

That or you can move the program to the root directory (c:\) or a more immediate folder (c:\temp) and then run the program. For instance,
cd c:\ (or cd c:\temp)
foo
 
  • #5
If my project were c:\documents and settings\(username)\desktop\foo, how would I find that out? How do I locate the location?
 
  • #6
wait nevermidn I found it
 
  • #7
See my comment about right-clicking on the .exe and opening up the properties to get the file path.

Now, as for a way to "fix" this "problem", I generally wait for user input (e.g. scanf in C or cin << in C++) at the end just before terminating.

EDIT: Along with printing a reminder to "Press any key to continue / terminate"
 
  • #8
Where is the .exe to right click?
 
  • #9
The specifics depend on which compiler / IDE you're using. However, it should be inside your project folder. Give consideration to the wait-for-user-input idea.
 
  • #10
what does "scanf in C or cin << in C++" mean
 
  • #11
UltimateSomni said:
what does "scanf in the C programming language or cin << in the C++ programming language" mean

Fixed that for you/me There should be an equivalent in whatever language you're programming in.
 
  • #12
Okay so I enter in "C:\Users\Fred\Documents\TEST.cpp" without quotes and the command prompt minimizes and nothing happens . What did I do wrong?
 
  • #13
scanf is a function in C's stdio that gets characters from the CLI.

cin << is the C++ equivalent.
 
  • #14
UltimateSomni said:
Okay so I enter in "C:\Users\Fred\Documents\TEST.cpp" without quotes and the command prompt minimizes and nothing happens . What did I do wrong?

You're not using the right file. .cpp is your source file, not the executable. Try entering just "C:\Users\Fred\Documents\TEST" (without the quotes)

I'll presume that you're going through the C++ tutorial that's stickied in this forum and going through the second assignment:
https://www.physicsforums.com/showthread.php?t=32703

Just before the return 0;, add a new line cin >> x;

The command prompt should now terminate whenever you hit enter.

EDIT: And yes, pay attention to which way the arrows point: I goofed up the direction up until this post.
 
  • #15
C:\Users\Fred\Documents\TEST does nothing
adding cin >> x does nothing
 
  • #16
Okay, please post your code. Make sure it's between
Code:
[ /code] tags, with the space removed from the second tag.
 
  • #17
I copy pasted exactly what is used for the task in part 2.
 
  • #18
This?

Code:
#include<iostream>

using namespace std;

int main( int argc, char *argv[]) {
	char myCharacter = 'z';
	cout << "The datatype is " << sizeof(int) << " bytes!" << endl;
	cout << "The variable has a value of " << myCharacter << endl;
	[b]cin >> myCharacter;[/b] 
	return 0;
}

Before compiling and running. If that still doesn't work, try cin.get(); instead. I probably should have said this right off the bat, but what are you using as your IDE / compiler?
 
Last edited:
  • #19
Yes, that. I'm using Dev-C++ 4.9.9.2

*cin.getch();* doesn't work either
 
  • #20
Is that program (the one from the tutorial) compatabile with windows 7?
 
  • #21
UltimateSomni said:
Yes, that. I'm using Dev-C++ 4.9.9.2

*cin.getch();* doesn't work either

What do you mean, it doesn't work? Please be more specific.

It's possible that your compiler puts the executable (test.exe) in a different directory than your source file (test.cpp) is in. I use a different compiler, Visual Studio 10, and it stores the executable two directories down from where the source file is.
 
  • #22
UltimateSomni said:
Yes, that. I'm using Dev-C++ 4.9.9.2

*cin.getch();* doesn't work either

Yes, that part was messed up. As per the edit, it should be cin.get() and not cin.getch() Are you getting any compiler error messages?

As well, there seems to be an issue with Dev-C++ running its own console program, instead of the standard one. If cin.get() STILL doesn't work, see FAQ points 1 and 2 for another work-around (note that this would only work in windows):
http://www.bloodshed.net/faq.html#1
 
  • #23
All right I'm pretty sure it is not compatible with windows 7. Do you any of you know a free compiler that works with C++ 64 bit?
 
  • #24
cin.get() worked. I love you!
 
  • #25
You can use the "Express" version of Microsoft Visual C++ for free, it's a cut down version of the full release, and you can't release your code commercially. I've used it in a brief foray into Source Modding (<3) and it was easy.
 

1. Why does the command prompt keep disappearing?

The command prompt may keep disappearing because the command you entered was completed successfully or because you accidentally pressed the "Enter" key. It could also be due to a glitch or error in the system.

2. How can I prevent the command prompt from disappearing?

To prevent the command prompt from disappearing, you can use the "pause" command after entering a command. This will keep the prompt open until you press a key to continue. You can also try running the command prompt as an administrator to avoid any potential issues.

3. What are some common commands I can try in the command prompt?

Some common commands you can try in the command prompt include "dir" to view the contents of a directory, "cd" to change directories, "copy" to copy files, and "del" to delete files. You can also use the "help" command to view a list of all available commands.

4. How can I troubleshoot issues with the command prompt?

If you are experiencing issues with the command prompt, you can try restarting your computer or running a virus scan to ensure there are no malicious programs affecting it. You can also try using different commands or running the command prompt in compatibility mode.

5. Is there a way to change the appearance of the command prompt?

Yes, there are several ways to change the appearance of the command prompt. You can change the font, font size, and color by right-clicking on the title bar and selecting "Properties." You can also use the "color" command to change the background and text colors.

Similar threads

  • Programming and Computer Science
Replies
1
Views
515
  • Programming and Computer Science
Replies
7
Views
5K
  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
5
Views
912
  • Programming and Computer Science
Replies
5
Views
2K
  • Computing and Technology
Replies
18
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top