visual studio.net / c++ question

Discussion in 'OT Technology' started by D1G1T4L, Jan 21, 2005.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    I am trying to write a simple program that just writes something on the screen using cout, the program terminates before i even see the output

    i tried using cin.get(); but the prompt still closes :o

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    	cout << " C++";
    	cout << "\n";
    	
    	
    	
    	cin.get();
    
    	return 0;
    }
    
     
  2. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Call a system pause.
     
  3. palbanes

    palbanes New Member

    Joined:
    Aug 14, 2003
    Messages:
    5,285
    Likes Received:
    0
    Location:
    Kansas City, MO
    insert a getch;
     
  4. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    why doesnt cin.get(); work
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Strange :dunno: Works fine for me when compiled using g++.
     
  6. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    I agree. I compiled it with no problems using g++
     
  7. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    err i think you guys misunderstood me, when you compile a program in visual studio, the program runs in a seperate window but it will automatically close the window when the program finishes, so in order for it not to close the window i am trying to use cin.get(); so i can hit enter to terminate it.... but that seems not to work
     
  8. beezurd

    beezurd New Member

    Joined:
    Aug 10, 2004
    Messages:
    820
    Likes Received:
    0
    Location:
    OC, CA
    trying setting a breakpoint, it'll break there before it executes (just click to the left of it and you should see a red dot appear)

    or with .NET you can use System.Console.Writeln() to output to the screen
     
  9. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    nm guys, i got it, was a mistake on my part (i wasnt creating an empty project i think)

    you can also use "start without debugging" and console will stay up
     
  10. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yeah, I know, when I ran it it just sat until I pressed a key, then ended.
     
  11. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    int g;
    cin >> g;

    or

    system("PAUSE");
     
  12. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    In visual .net?
    Instead of Debug-> Start

    Try Debug -> Start without debugging.
     
  13. SEPHROTH64

    SEPHROTH64 Guest

    ctrl + f5
     

Share This Page