Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ in Visual Studio.NET

C++ in Visual Studio.NET

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiohelpc++
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Liang
    wrote on last edited by
    #1

    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

    T C N 3 Replies Last reply
    0
    • J J Liang

      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

      T Offline
      T Offline
      T1TAN
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • J J Liang

        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

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        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;

        J 1 Reply Last reply
        0
        • J J Liang

          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

          N Offline
          N Offline
          Neagoe Gabriel
          wrote on last edited by
          #4

          add #include add before return 0 getch();:) NG

          J 1 Reply Last reply
          0
          • T T1TAN

            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.

            J Offline
            J Offline
            J Liang
            wrote on last edited by
            #5

            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

            T 1 Reply Last reply
            0
            • C Cedric Moonen

              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;

              J Offline
              J Offline
              J Liang
              wrote on last edited by
              #6

              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

              _ 1 Reply Last reply
              0
              • J J Liang

                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

                T Offline
                T Offline
                T1TAN
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • N Neagoe Gabriel

                  add #include add before return 0 getch();:) NG

                  J Offline
                  J Offline
                  J Liang
                  wrote on last edited by
                  #8

                  Hey, thanks, it works :-D! I think I really need time to get adapted to VS.NET. Jay

                  1 Reply Last reply
                  0
                  • J J Liang

                    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

                    _ Offline
                    _ Offline
                    _rubinho_
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups