Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Programming error, need help?
Ok this is very basic stuff, I'm learning to program via the internet, I've done the hello world exercise, I've moved onto variables and got basic math going. I use Visual C++ express edition, and in one of their videos I had to include a
char variablehere[100];
cin.getline(variablehere,100);
I need to use that in order to keep the window from just popping up and disappearing, but every online tutorial I've been to has no such mention of this, and if I follow the websites tutorials, the window just closes. So adding in this code to keep the window open to the online tutorial has worked, until I got to user input type stuff....
It works, and displays all but it crashes everytime, and If I make it into an .exe I get an error "hello world.exe" has stopped working
here is the code
#include "hello world.h"
using namespace std;
int main (int argc, char* argv[])
{
int i;
cout << "Please Enter Your Age:";
cin >> i;
cout << "So you're age is " << i;
cout<<argv[100];
char things[100];
cin.getline(things,100);
return 0;
}
and I have a header that is:
#include <iostream>
Ok so also that one line cout<<argv[100]; wasn't needed in all my other attemps at displaying regular messages, but when I got to user input the window just closes if I don't include it.
any help?
2 Answers
- Shadow WolfLv 61 decade agoFavorite Answer
A DOS or Command window closes when the program exits because it is invoked as part of running the program.
If you don't want to add any extra code, simply open the DOS or command window and then execute the program from the command line. Since you opened the window and it wasn't a part of executing your program, the window will remain open and you'll be able to see your results.
The next problem is you'll need to look at the command line commands. You'll probably need to change directories using the CD command.
Shadow Wolf
- RatchetrLv 71 decade ago
What is this line of code?:
cout<<argv[100];
Delete it, and you will probably stop crashing.
argv is an array with all the arguments passed to your program. You probably aren't passing any arguments. But argv[100] will try to access the 100'th argument to the program. Unless you really have 100 arguments, doing that could very easily crash.
Here's another hint:
In Visual Studio, move the cursor to the closing } in main.
Hit F9. A red dot should appear on the left. That's a breakpoint.
Now hit F5. That will start the program in debug mode.
If your program crashes, Visual studio should stop and highlight where the program crashed.
If your program doesn't crash, Visual Studio will stop and show you that it reached your breakpoint. (Yellow arrow on top of the red dot). At that point you can click on the window your program is running in, and see the output. Hit F5 again to shut down the program.