C++ in Visual Studio.NET
-
I recently installed VS.NET and wanted to create a C++ program, I selected Win32 Console Project to start with. I have one while loop and one for loop. The while loop execute first then follow by the for loop. The problem is after executing the while loop, it closes the window with the black background and will not show me the result. I'd checked my program, it actually run the for loop but the window just close before it can show me anything. This is my test code: #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int myArray[100]; int count = 0; int number = 0; cout << "Please enter some number (-1 to terminate): " << endl; while (number != -1) { cin >> number; myArray[count] = number; count++; } cout << "The numbers you just typed are: "; for (int counter = 0; counter < count; counter++) { cout << myArray[counter] << " "; } cout << endl; return 0; } Thanks to anyone that can help me with this so I can start practising my programming skill =) Jay
-
I recently installed VS.NET and wanted to create a C++ program, I selected Win32 Console Project to start with. I have one while loop and one for loop. The while loop execute first then follow by the for loop. The problem is after executing the while loop, it closes the window with the black background and will not show me the result. I'd checked my program, it actually run the for loop but the window just close before it can show me anything. This is my test code: #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int myArray[100]; int count = 0; int number = 0; cout << "Please enter some number (-1 to terminate): " << endl; while (number != -1) { cin >> number; myArray[count] = number; count++; } cout << "The numbers you just typed are: "; for (int counter = 0; counter < count; counter++) { cout << myArray[counter] << " "; } cout << endl; return 0; } Thanks to anyone that can help me with this so I can start practising my programming skill =) Jay
I'm not completely sure, but you might try adding this just before
return 0;
#ifndef _DEBUG cout << "\n\n\tPress any key to continue\n\tor any other key to quit.."; getch(); #endif //_DEBUG
Good luck with programming ;) --- http://sprdsoft.cmar-net.org - We Sprd You Softly Our site features contents and several images. All of this is very weird. In the end, war is not about who's right, it's about who's left. -
I recently installed VS.NET and wanted to create a C++ program, I selected Win32 Console Project to start with. I have one while loop and one for loop. The while loop execute first then follow by the for loop. The problem is after executing the while loop, it closes the window with the black background and will not show me the result. I'd checked my program, it actually run the for loop but the window just close before it can show me anything. This is my test code: #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int myArray[100]; int count = 0; int number = 0; cout << "Please enter some number (-1 to terminate): " << endl; while (number != -1) { cin >> number; myArray[count] = number; count++; } cout << "The numbers you just typed are: "; for (int counter = 0; counter < count; counter++) { cout << myArray[counter] << " "; } cout << endl; return 0; } Thanks to anyone that can help me with this so I can start practising my programming skill =) Jay
That's normal: your program is terminated. Maybe what you can do is add a line at the end of your prog that will wait until the user presses a key. You can use getch for that:
cout << "Press a key to continue"; getcg(); return 0;
-
I recently installed VS.NET and wanted to create a C++ program, I selected Win32 Console Project to start with. I have one while loop and one for loop. The while loop execute first then follow by the for loop. The problem is after executing the while loop, it closes the window with the black background and will not show me the result. I'd checked my program, it actually run the for loop but the window just close before it can show me anything. This is my test code: #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int myArray[100]; int count = 0; int number = 0; cout << "Please enter some number (-1 to terminate): " << endl; while (number != -1) { cin >> number; myArray[count] = number; count++; } cout << "The numbers you just typed are: "; for (int counter = 0; counter < count; counter++) { cout << myArray[counter] << " "; } cout << endl; return 0; } Thanks to anyone that can help me with this so I can start practising my programming skill =) Jay
add #include add before return 0 getch();:) NG
-
I'm not completely sure, but you might try adding this just before
return 0;
#ifndef _DEBUG cout << "\n\n\tPress any key to continue\n\tor any other key to quit.."; getch(); #endif //_DEBUG
Good luck with programming ;) --- http://sprdsoft.cmar-net.org - We Sprd You Softly Our site features contents and several images. All of this is very weird. In the end, war is not about who's right, it's about who's left. -
That's normal: your program is terminated. Maybe what you can do is add a line at the end of your prog that will wait until the user presses a key. You can use getch for that:
cout << "Press a key to continue"; getcg(); return 0;
-
Thanks for the reply, I'd tested it, the problem is still the same, really don't understand why this is so complicated compare to Visual C++ 6.0
Have you tried removing
#ifndef _DEBUG
and#endif //_DEBUG
? That's a really annoying problem.:sigh: --- http://sprdsoft.cmar-net.org - We Sprd You Softly Our site features contents and several images. All of this is very weird. In the end, war is not about who's right, it's about who's left. -
add #include add before return 0 getch();:) NG
-
Thanks for the reply, I got this error message when I do this: identifier not found,even with argument dependent lookup. Anyway,I shall see what I can find from the Internet
That's because there was a typo in the original message, there's no such thing as getcg() it should be getch(). "Visual SourceSafe? It would be safer to print out all your code, run it through a shredder, and set it on fire." - Fitz -- modified at 10:19 Tuesday 6th September, 2005