Thread: I'm having a problem running a dot execute file

  1. #1
    Registered User
    Join Date
    Jul 2014
    Location
    Central Arizona
    Posts
    61

    I'm having a problem running a dot execute file

    I've compiles and ran this simple program using code:blocks and it works fine. But if I run the dot exe version the console window closes immediately and I want to fix it to stay open so a user can read it. Note I've used cin.ignore (); and cin.get (); but these function don't help. What am I doing wrong?


    Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
    int thisisanumber;
    cout << "Please enter a number: ";
    cin >> thisisanumber;
    cin.ignore ();
    cin.get ();
    cout << "You entered: " << thisisanumber << "\n";
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Note I've used cin.ignore (); and cin.get ();
    Perhaps you should put them after your last line of output.

    Are you saying that if you open a separate console, then type in ./prog.exe, that the whole console window closes?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Location
    Central Arizona
    Posts
    61
    Quote Originally Posted by Salem View Post
    > Note I've used cin.ignore (); and cin.get ();
    Perhaps you should put them after your last line of output.

    Are you saying that if you open a separate console, then type in ./prog.exe, that the whole console window closes?
    Thanks I'll see if moving these functions to the last output works.
    NO! I'm trying to run the program using the program (name.exe) file that is generated after compiling it. I want to be able to email a copy of the (name.exe) to my son and have it work on his Windows PC
    Last edited by papagym177; 01-08-2015 at 03:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2011, 12:46 AM
  2. Execute external file
    By Malefaust in forum C Programming
    Replies: 3
    Last Post: 07-03-2006, 04:20 PM
  3. Execute Problem
    By Marc Sharp in forum C Programming
    Replies: 4
    Last Post: 11-22-2003, 02:25 AM
  4. How do I execute an external EXE file
    By Scripter in forum C Programming
    Replies: 1
    Last Post: 11-09-2002, 07:02 AM
  5. How to execute file commands?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 12-23-2001, 01:31 AM